-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome_Free_Strings.cpp
More file actions
104 lines (92 loc) · 2.28 KB
/
Palindrome_Free_Strings.cpp
File metadata and controls
104 lines (92 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ff first
#define endl '\n'
#define ss second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fo(i, a, b) for (int i = a; i < b; i++)
#define foe(i, a, b) for (int i = a; i <= b; i++)
const int MOD1 = 998244353;
const int MOD = 1000000007;
#define INF 1e18
#define PI 3.141592653589793238462
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef unsigned long long ull;
// Policy Based Data Structures
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using multi_ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
string temp;
bool isPalin(int lo, int hi)
{
string s;
foe(i, lo, hi) s.pb(temp[i]);
string s1 = s;
reverse(all(s1));
if (s == s1)
return true;
else
return false;
}
int main()
{
int t;
cin >> t;
fo(tt, 0, t)
{
cout << "Case #" << tt + 1 << ": ";
int n;
cin >> n;
string s;
cin >> s;
vi pos;
fo(i, 0, n) if (s[i] == '?') pos.pb(i);
bool flag = false;
fo(i, 0, (1 << pos.size()))
{
fo(j, 0, pos.size())
{
if (i & (1 << j))
s[pos[j]] = '1';
else
s[pos[j]] = '0';
}
temp = s;
// size 5
bool f5 = false, f6 = false;
for (int i = 0; i + 4 < n; i++)
{
if (isPalin(i, i + 4))
f5 = true;
}
for (int i = 0; i + 5 < n; i++)
{
if (isPalin(i, i + 5))
f6 = true;
}
if (!f5 && !f6)
{
flag = true;
break;
}
}
if (flag)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
}
return 0;
}