#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int black[N], white[N], prb[N], prw[N];
int getwhite(int l, int r){
return prw[r]-prw[l-1];
}
int getblack(int l, int r){
return prb[r]-prb[l-1];
}
bool checkvalid(int l, int r){
if(getwhite(l, r))return 0;
return 1;
}
string solve_puzzle(string s, vector<int> c) {
int n = s.size();
int m = c.size();
for(int i=1; i<=n; i++){
prb[i]=prb[i-1];
prw[i]=prw[i-1];
if(s[i-1]=='_')prw[i]++;
if(s[i-1]=='X')prb[i]++;
}
int pos[m];
int p=1;
int cnt = 0;
for(int i = 0; i < m; i++){
while(!checkvalid(p, p+c[i]-1))p++;
pos[i] = p;
cnt += getblack(p, p+c[i]-1);
p += c[i]+1;
}
if(cnt==prb[n]){
white[1]++;
for(int i=0; i<m; i++){
black[pos[i]]++;
black[pos[i]+c[i]]--;
white[pos[i]]--;
white[pos[i]+c[i]]++;
}
}
int mv = 0;
while(true){
bool changed = 0;
int nxt;
if(mv==m-1)nxt=n;
else nxt=pos[mv+1]-2;
for(int i = pos[mv]+c[mv]; i<=nxt; i++){
if(s[i]=='_')continue;
if(checkvalid(i-c[mv]+1, i)){
changed = 1;
cnt-=getblack(pos[mv], pos[mv]+c[mv]-1);
cnt+=getblack(i-c[mv]+1, i);
pos[mv]=i-c[mv]+1;
if(cnt==prb[n]){
white[1]++;
for(int j=0; j < m; j++){
white[pos[j]]--;
white[pos[j]+c[j]]++;
black[pos[j]]++;
black[pos[j]+c[j]]--;
}
}
break;
}
}
if(changed)mv=max(mv-1, 0);
else{
if(mv==m-1)break;
else mv++;
}
}
for(int i = 2; i <= n; i++){
white[i]+=white[i-1];
black[i]+=black[i-1];
}
string ret = "";
for(int i=1; i<=n; i++){
if(white[i] && black[i])ret+='?';
else if(white[i])ret+='_';
else ret+='X';
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
344 KB |
n = 20, m = 5 |
9 |
Correct |
0 ms |
344 KB |
n = 18, m = 3 |
10 |
Correct |
1 ms |
348 KB |
n = 17, m = 2 |
11 |
Correct |
0 ms |
348 KB |
n = 20, m = 2 |
12 |
Correct |
1 ms |
348 KB |
n = 17, m = 4 |
13 |
Correct |
1 ms |
348 KB |
n = 17, m = 6 |
14 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
15 |
Correct |
0 ms |
348 KB |
n = 17, m = 4 |
16 |
Correct |
0 ms |
348 KB |
n = 13, m = 3 |
17 |
Correct |
0 ms |
348 KB |
n = 18, m = 4 |
18 |
Correct |
0 ms |
348 KB |
n = 20, m = 10 |
19 |
Correct |
1 ms |
348 KB |
n = 19, m = 10 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
344 KB |
n = 20, m = 5 |
9 |
Correct |
0 ms |
344 KB |
n = 18, m = 3 |
10 |
Correct |
1 ms |
348 KB |
n = 17, m = 2 |
11 |
Correct |
0 ms |
348 KB |
n = 20, m = 2 |
12 |
Correct |
1 ms |
348 KB |
n = 17, m = 4 |
13 |
Correct |
1 ms |
348 KB |
n = 17, m = 6 |
14 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
15 |
Correct |
0 ms |
348 KB |
n = 17, m = 4 |
16 |
Correct |
0 ms |
348 KB |
n = 13, m = 3 |
17 |
Correct |
0 ms |
348 KB |
n = 18, m = 4 |
18 |
Correct |
0 ms |
348 KB |
n = 20, m = 10 |
19 |
Correct |
1 ms |
348 KB |
n = 19, m = 10 |
20 |
Correct |
1 ms |
348 KB |
n = 100, m = 5 |
21 |
Correct |
0 ms |
348 KB |
n = 90, m = 3 |
22 |
Correct |
0 ms |
348 KB |
n = 86, m = 2 |
23 |
Correct |
0 ms |
348 KB |
n = 81, m = 4 |
24 |
Correct |
1 ms |
348 KB |
n = 89, m = 10 |
25 |
Correct |
1 ms |
344 KB |
n = 81, m = 23 |
26 |
Correct |
1 ms |
348 KB |
n = 86, m = 8 |
27 |
Correct |
0 ms |
348 KB |
n = 53, m = 22 |
28 |
Correct |
0 ms |
428 KB |
n = 89, m = 35 |
29 |
Correct |
0 ms |
344 KB |
n = 63, m = 25 |
30 |
Correct |
0 ms |
348 KB |
n = 100, m = 50 |
31 |
Correct |
0 ms |
348 KB |
n = 99, m = 50 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
344 KB |
n = 20, m = 5 |
9 |
Correct |
0 ms |
344 KB |
n = 18, m = 3 |
10 |
Correct |
1 ms |
348 KB |
n = 17, m = 2 |
11 |
Correct |
0 ms |
348 KB |
n = 20, m = 2 |
12 |
Correct |
1 ms |
348 KB |
n = 17, m = 4 |
13 |
Correct |
1 ms |
348 KB |
n = 17, m = 6 |
14 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
15 |
Correct |
0 ms |
348 KB |
n = 17, m = 4 |
16 |
Correct |
0 ms |
348 KB |
n = 13, m = 3 |
17 |
Correct |
0 ms |
348 KB |
n = 18, m = 4 |
18 |
Correct |
0 ms |
348 KB |
n = 20, m = 10 |
19 |
Correct |
1 ms |
348 KB |
n = 19, m = 10 |
20 |
Correct |
1 ms |
348 KB |
n = 100, m = 5 |
21 |
Correct |
0 ms |
348 KB |
n = 90, m = 3 |
22 |
Correct |
0 ms |
348 KB |
n = 86, m = 2 |
23 |
Correct |
0 ms |
348 KB |
n = 81, m = 4 |
24 |
Correct |
1 ms |
348 KB |
n = 89, m = 10 |
25 |
Correct |
1 ms |
344 KB |
n = 81, m = 23 |
26 |
Correct |
1 ms |
348 KB |
n = 86, m = 8 |
27 |
Correct |
0 ms |
348 KB |
n = 53, m = 22 |
28 |
Correct |
0 ms |
428 KB |
n = 89, m = 35 |
29 |
Correct |
0 ms |
344 KB |
n = 63, m = 25 |
30 |
Correct |
0 ms |
348 KB |
n = 100, m = 50 |
31 |
Correct |
0 ms |
348 KB |
n = 99, m = 50 |
32 |
Incorrect |
0 ms |
348 KB |
char #0 differ - expected: '?', found: 'X' |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
344 KB |
n = 20, m = 5 |
9 |
Correct |
0 ms |
344 KB |
n = 18, m = 3 |
10 |
Correct |
1 ms |
348 KB |
n = 17, m = 2 |
11 |
Correct |
0 ms |
348 KB |
n = 20, m = 2 |
12 |
Correct |
1 ms |
348 KB |
n = 17, m = 4 |
13 |
Correct |
1 ms |
348 KB |
n = 17, m = 6 |
14 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
15 |
Correct |
0 ms |
348 KB |
n = 17, m = 4 |
16 |
Correct |
0 ms |
348 KB |
n = 13, m = 3 |
17 |
Correct |
0 ms |
348 KB |
n = 18, m = 4 |
18 |
Correct |
0 ms |
348 KB |
n = 20, m = 10 |
19 |
Correct |
1 ms |
348 KB |
n = 19, m = 10 |
20 |
Correct |
1 ms |
348 KB |
n = 100, m = 5 |
21 |
Correct |
0 ms |
348 KB |
n = 90, m = 3 |
22 |
Correct |
0 ms |
348 KB |
n = 86, m = 2 |
23 |
Correct |
0 ms |
348 KB |
n = 81, m = 4 |
24 |
Correct |
1 ms |
348 KB |
n = 89, m = 10 |
25 |
Correct |
1 ms |
344 KB |
n = 81, m = 23 |
26 |
Correct |
1 ms |
348 KB |
n = 86, m = 8 |
27 |
Correct |
0 ms |
348 KB |
n = 53, m = 22 |
28 |
Correct |
0 ms |
428 KB |
n = 89, m = 35 |
29 |
Correct |
0 ms |
344 KB |
n = 63, m = 25 |
30 |
Correct |
0 ms |
348 KB |
n = 100, m = 50 |
31 |
Correct |
0 ms |
348 KB |
n = 99, m = 50 |
32 |
Incorrect |
0 ms |
348 KB |
char #0 differ - expected: '?', found: 'X' |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
344 KB |
n = 20, m = 5 |
9 |
Correct |
0 ms |
344 KB |
n = 18, m = 3 |
10 |
Correct |
1 ms |
348 KB |
n = 17, m = 2 |
11 |
Correct |
0 ms |
348 KB |
n = 20, m = 2 |
12 |
Correct |
1 ms |
348 KB |
n = 17, m = 4 |
13 |
Correct |
1 ms |
348 KB |
n = 17, m = 6 |
14 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
15 |
Correct |
0 ms |
348 KB |
n = 17, m = 4 |
16 |
Correct |
0 ms |
348 KB |
n = 13, m = 3 |
17 |
Correct |
0 ms |
348 KB |
n = 18, m = 4 |
18 |
Correct |
0 ms |
348 KB |
n = 20, m = 10 |
19 |
Correct |
1 ms |
348 KB |
n = 19, m = 10 |
20 |
Correct |
1 ms |
348 KB |
n = 100, m = 5 |
21 |
Correct |
0 ms |
348 KB |
n = 90, m = 3 |
22 |
Correct |
0 ms |
348 KB |
n = 86, m = 2 |
23 |
Correct |
0 ms |
348 KB |
n = 81, m = 4 |
24 |
Correct |
1 ms |
348 KB |
n = 89, m = 10 |
25 |
Correct |
1 ms |
344 KB |
n = 81, m = 23 |
26 |
Correct |
1 ms |
348 KB |
n = 86, m = 8 |
27 |
Correct |
0 ms |
348 KB |
n = 53, m = 22 |
28 |
Correct |
0 ms |
428 KB |
n = 89, m = 35 |
29 |
Correct |
0 ms |
344 KB |
n = 63, m = 25 |
30 |
Correct |
0 ms |
348 KB |
n = 100, m = 50 |
31 |
Correct |
0 ms |
348 KB |
n = 99, m = 50 |
32 |
Incorrect |
0 ms |
348 KB |
char #0 differ - expected: '?', found: 'X' |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
n = 13, m = 1 |
2 |
Correct |
0 ms |
348 KB |
n = 18, m = 1 |
3 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
4 |
Correct |
0 ms |
348 KB |
n = 1, m = 1 |
5 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
6 |
Correct |
0 ms |
348 KB |
n = 20, m = 1 |
7 |
Correct |
1 ms |
348 KB |
n = 20, m = 1 |
8 |
Correct |
1 ms |
344 KB |
n = 20, m = 5 |
9 |
Correct |
0 ms |
344 KB |
n = 18, m = 3 |
10 |
Correct |
1 ms |
348 KB |
n = 17, m = 2 |
11 |
Correct |
0 ms |
348 KB |
n = 20, m = 2 |
12 |
Correct |
1 ms |
348 KB |
n = 17, m = 4 |
13 |
Correct |
1 ms |
348 KB |
n = 17, m = 6 |
14 |
Correct |
0 ms |
348 KB |
n = 17, m = 1 |
15 |
Correct |
0 ms |
348 KB |
n = 17, m = 4 |
16 |
Correct |
0 ms |
348 KB |
n = 13, m = 3 |
17 |
Correct |
0 ms |
348 KB |
n = 18, m = 4 |
18 |
Correct |
0 ms |
348 KB |
n = 20, m = 10 |
19 |
Correct |
1 ms |
348 KB |
n = 19, m = 10 |
20 |
Correct |
1 ms |
348 KB |
n = 100, m = 5 |
21 |
Correct |
0 ms |
348 KB |
n = 90, m = 3 |
22 |
Correct |
0 ms |
348 KB |
n = 86, m = 2 |
23 |
Correct |
0 ms |
348 KB |
n = 81, m = 4 |
24 |
Correct |
1 ms |
348 KB |
n = 89, m = 10 |
25 |
Correct |
1 ms |
344 KB |
n = 81, m = 23 |
26 |
Correct |
1 ms |
348 KB |
n = 86, m = 8 |
27 |
Correct |
0 ms |
348 KB |
n = 53, m = 22 |
28 |
Correct |
0 ms |
428 KB |
n = 89, m = 35 |
29 |
Correct |
0 ms |
344 KB |
n = 63, m = 25 |
30 |
Correct |
0 ms |
348 KB |
n = 100, m = 50 |
31 |
Correct |
0 ms |
348 KB |
n = 99, m = 50 |
32 |
Incorrect |
0 ms |
348 KB |
char #0 differ - expected: '?', found: 'X' |
33 |
Halted |
0 ms |
0 KB |
- |