-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2022_c.cpp
More file actions
51 lines (47 loc) · 1.02 KB
/
2022_c.cpp
File metadata and controls
51 lines (47 loc) · 1.02 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
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
void solve(){
int N; string str;
cin >> N >> str;
bool dp[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) dp[i][j] = false;
dp[i][i] = true;
}
for (int count = 1; count < N; count++) {
for (int i = 0; i < N; i++) {
int j = i + count;
if (j >= N) break;
if (dp[i+1][j-1]) {
if (str[i] == '?') {
if (str[j] == '1') str[i] = '0';
else str[i] = '1';
}
if (str[j] == '?') {
if (str[i] == '1') str[j] = '0';
else str[j] = '1';
}
if (str[j] == str[i]) {
if (count >= 4) {
cout << "IMPOSSIBLE";
return;
}
dp[i][j] = dp[i+1][j-1];
}
}
}
}
cout << "POSSIBLE";
}
int main(){
cout.tie(0);cin.tie(0)->sync_with_stdio(0);
int t; cin >> t;
for (int i = 1; i <= t; i++) {
cout << "Case #"<<i<<": ";
solve();
cout << "\n";
}
return 0;
}