#include <bits/stdc++.h>
using namespace std;
const int mxL=20, mxQ=1e6;
int l, q, dp[2][1<<mxL];
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> l >> q >> s;
for(int j=0; j<2; ++j) {
for(int i=0; i<1<<l; ++i)
dp[j][i]=s[i]-'0';
for(int k=0; k<l; ++k)
for(int i=0; i<1<<l; ++i)
if(i>>k&1^j)
dp[j][i]+=dp[j][i^1<<k];
}
while(q--) {
string t;
cin >> t;
int na=0, nb=0, nc=0, ma=0, mb=0, mc=0, ans=0;
for(int i=0; i<l; ++i) {
if(t[i]=='0') {
++na;
ma|=1<<(l-1-i);
} else if(t[i]=='1') {
++nb;
mb|=1<<(l-1-i);
} else {
++nc;
mc|=1<<(l-1-i);
}
}
if(na<nc||nb<nc) {
bool sw=0;
if(nb>na) {
swap(nb, na);
swap(mb, ma);
sw=1;
}
for(int i=mb; ; i=(i-1)&mb) {
ans+=dp[sw][(sw?(1<<l)-1:0)^i^mb^mc]*(__builtin_popcount(i)&1?-1:1);
if(!i)
break;
}
} else {
for(int i=mc; ; i=(i-1)&mc) {
ans+=s[i|mb]-'0';
if(!i)
break;
}
}
cout << ans << "\n";
}
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:18:12: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
if(i>>k&1^j)
~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
3 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
3 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
804 KB |
Output is correct |
11 |
Correct |
348 ms |
15540 KB |
Output is correct |
12 |
Correct |
282 ms |
17756 KB |
Output is correct |
13 |
Correct |
313 ms |
17756 KB |
Output is correct |
14 |
Correct |
300 ms |
17756 KB |
Output is correct |
15 |
Correct |
311 ms |
18636 KB |
Output is correct |
16 |
Correct |
323 ms |
18636 KB |
Output is correct |
17 |
Correct |
339 ms |
19404 KB |
Output is correct |
18 |
Correct |
269 ms |
21132 KB |
Output is correct |
19 |
Correct |
248 ms |
21132 KB |
Output is correct |
20 |
Correct |
282 ms |
21132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
3 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
804 KB |
Output is correct |
11 |
Correct |
348 ms |
15540 KB |
Output is correct |
12 |
Correct |
282 ms |
17756 KB |
Output is correct |
13 |
Correct |
313 ms |
17756 KB |
Output is correct |
14 |
Correct |
300 ms |
17756 KB |
Output is correct |
15 |
Correct |
311 ms |
18636 KB |
Output is correct |
16 |
Correct |
323 ms |
18636 KB |
Output is correct |
17 |
Correct |
339 ms |
19404 KB |
Output is correct |
18 |
Correct |
269 ms |
21132 KB |
Output is correct |
19 |
Correct |
248 ms |
21132 KB |
Output is correct |
20 |
Correct |
282 ms |
21132 KB |
Output is correct |
21 |
Correct |
317 ms |
21132 KB |
Output is correct |
22 |
Correct |
368 ms |
21132 KB |
Output is correct |
23 |
Correct |
309 ms |
21132 KB |
Output is correct |
24 |
Correct |
373 ms |
21132 KB |
Output is correct |
25 |
Correct |
281 ms |
21164 KB |
Output is correct |
26 |
Correct |
406 ms |
21164 KB |
Output is correct |
27 |
Correct |
411 ms |
21164 KB |
Output is correct |
28 |
Correct |
219 ms |
22188 KB |
Output is correct |
29 |
Correct |
300 ms |
22188 KB |
Output is correct |
30 |
Correct |
335 ms |
22188 KB |
Output is correct |
31 |
Correct |
354 ms |
22188 KB |
Output is correct |
32 |
Correct |
402 ms |
22188 KB |
Output is correct |
33 |
Correct |
321 ms |
22188 KB |
Output is correct |
34 |
Correct |
359 ms |
22188 KB |
Output is correct |
35 |
Correct |
382 ms |
22188 KB |
Output is correct |
36 |
Correct |
226 ms |
32016 KB |
Output is correct |
37 |
Correct |
278 ms |
47692 KB |
Output is correct |
38 |
Correct |
288 ms |
59500 KB |
Output is correct |
39 |
Runtime error |
376 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
3 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
804 KB |
Output is correct |
11 |
Runtime error |
127 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
572 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
804 KB |
Output is correct |
9 |
Correct |
3 ms |
804 KB |
Output is correct |
10 |
Correct |
2 ms |
804 KB |
Output is correct |
11 |
Correct |
348 ms |
15540 KB |
Output is correct |
12 |
Correct |
282 ms |
17756 KB |
Output is correct |
13 |
Correct |
313 ms |
17756 KB |
Output is correct |
14 |
Correct |
300 ms |
17756 KB |
Output is correct |
15 |
Correct |
311 ms |
18636 KB |
Output is correct |
16 |
Correct |
323 ms |
18636 KB |
Output is correct |
17 |
Correct |
339 ms |
19404 KB |
Output is correct |
18 |
Correct |
269 ms |
21132 KB |
Output is correct |
19 |
Correct |
248 ms |
21132 KB |
Output is correct |
20 |
Correct |
282 ms |
21132 KB |
Output is correct |
21 |
Correct |
317 ms |
21132 KB |
Output is correct |
22 |
Correct |
368 ms |
21132 KB |
Output is correct |
23 |
Correct |
309 ms |
21132 KB |
Output is correct |
24 |
Correct |
373 ms |
21132 KB |
Output is correct |
25 |
Correct |
281 ms |
21164 KB |
Output is correct |
26 |
Correct |
406 ms |
21164 KB |
Output is correct |
27 |
Correct |
411 ms |
21164 KB |
Output is correct |
28 |
Correct |
219 ms |
22188 KB |
Output is correct |
29 |
Correct |
300 ms |
22188 KB |
Output is correct |
30 |
Correct |
335 ms |
22188 KB |
Output is correct |
31 |
Correct |
354 ms |
22188 KB |
Output is correct |
32 |
Correct |
402 ms |
22188 KB |
Output is correct |
33 |
Correct |
321 ms |
22188 KB |
Output is correct |
34 |
Correct |
359 ms |
22188 KB |
Output is correct |
35 |
Correct |
382 ms |
22188 KB |
Output is correct |
36 |
Correct |
226 ms |
32016 KB |
Output is correct |
37 |
Correct |
278 ms |
47692 KB |
Output is correct |
38 |
Correct |
288 ms |
59500 KB |
Output is correct |
39 |
Runtime error |
376 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
40 |
Halted |
0 ms |
0 KB |
- |