#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 |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
712 KB |
Output is correct |
8 |
Correct |
3 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
3 ms |
712 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 |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
712 KB |
Output is correct |
8 |
Correct |
3 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
3 ms |
712 KB |
Output is correct |
11 |
Correct |
251 ms |
5216 KB |
Output is correct |
12 |
Correct |
340 ms |
5216 KB |
Output is correct |
13 |
Correct |
326 ms |
5216 KB |
Output is correct |
14 |
Correct |
388 ms |
5216 KB |
Output is correct |
15 |
Correct |
346 ms |
5612 KB |
Output is correct |
16 |
Correct |
292 ms |
5612 KB |
Output is correct |
17 |
Correct |
286 ms |
5620 KB |
Output is correct |
18 |
Correct |
194 ms |
7452 KB |
Output is correct |
19 |
Correct |
239 ms |
7452 KB |
Output is correct |
20 |
Correct |
248 ms |
7452 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 |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
712 KB |
Output is correct |
8 |
Correct |
3 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
3 ms |
712 KB |
Output is correct |
11 |
Correct |
251 ms |
5216 KB |
Output is correct |
12 |
Correct |
340 ms |
5216 KB |
Output is correct |
13 |
Correct |
326 ms |
5216 KB |
Output is correct |
14 |
Correct |
388 ms |
5216 KB |
Output is correct |
15 |
Correct |
346 ms |
5612 KB |
Output is correct |
16 |
Correct |
292 ms |
5612 KB |
Output is correct |
17 |
Correct |
286 ms |
5620 KB |
Output is correct |
18 |
Correct |
194 ms |
7452 KB |
Output is correct |
19 |
Correct |
239 ms |
7452 KB |
Output is correct |
20 |
Correct |
248 ms |
7452 KB |
Output is correct |
21 |
Correct |
328 ms |
7452 KB |
Output is correct |
22 |
Correct |
319 ms |
7452 KB |
Output is correct |
23 |
Correct |
377 ms |
7452 KB |
Output is correct |
24 |
Correct |
308 ms |
7452 KB |
Output is correct |
25 |
Correct |
286 ms |
7892 KB |
Output is correct |
26 |
Correct |
372 ms |
7892 KB |
Output is correct |
27 |
Correct |
339 ms |
7892 KB |
Output is correct |
28 |
Correct |
207 ms |
9048 KB |
Output is correct |
29 |
Correct |
297 ms |
9048 KB |
Output is correct |
30 |
Correct |
305 ms |
9048 KB |
Output is correct |
31 |
Correct |
312 ms |
9048 KB |
Output is correct |
32 |
Correct |
420 ms |
9048 KB |
Output is correct |
33 |
Correct |
326 ms |
9048 KB |
Output is correct |
34 |
Correct |
375 ms |
9048 KB |
Output is correct |
35 |
Correct |
340 ms |
9048 KB |
Output is correct |
36 |
Correct |
232 ms |
9048 KB |
Output is correct |
37 |
Correct |
261 ms |
9048 KB |
Output is correct |
38 |
Correct |
254 ms |
9048 KB |
Output is correct |
39 |
Correct |
326 ms |
9048 KB |
Output is correct |
40 |
Correct |
334 ms |
9048 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 |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
712 KB |
Output is correct |
8 |
Correct |
3 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
3 ms |
712 KB |
Output is correct |
11 |
Correct |
122 ms |
13108 KB |
Output is correct |
12 |
Correct |
128 ms |
13108 KB |
Output is correct |
13 |
Correct |
132 ms |
13108 KB |
Output is correct |
14 |
Correct |
194 ms |
13108 KB |
Output is correct |
15 |
Correct |
170 ms |
13108 KB |
Output is correct |
16 |
Correct |
162 ms |
13108 KB |
Output is correct |
17 |
Correct |
124 ms |
13108 KB |
Output is correct |
18 |
Correct |
101 ms |
13148 KB |
Output is correct |
19 |
Correct |
120 ms |
13148 KB |
Output is correct |
20 |
Correct |
122 ms |
13148 KB |
Output is correct |
21 |
Correct |
130 ms |
13192 KB |
Output is correct |
22 |
Correct |
133 ms |
13192 KB |
Output is correct |
23 |
Correct |
111 ms |
13192 KB |
Output is correct |
24 |
Correct |
137 ms |
13192 KB |
Output is correct |
25 |
Correct |
153 ms |
13192 KB |
Output is correct |
26 |
Correct |
99 ms |
13244 KB |
Output is correct |
27 |
Correct |
107 ms |
13284 KB |
Output is correct |
28 |
Correct |
139 ms |
13292 KB |
Output is correct |
29 |
Correct |
129 ms |
13312 KB |
Output is correct |
30 |
Correct |
122 ms |
13412 KB |
Output is correct |
31 |
Correct |
119 ms |
13412 KB |
Output is correct |
32 |
Correct |
131 ms |
13412 KB |
Output is correct |
33 |
Correct |
165 ms |
13412 KB |
Output is correct |
34 |
Correct |
94 ms |
13412 KB |
Output is correct |
35 |
Correct |
127 ms |
13464 KB |
Output is correct |
36 |
Correct |
179 ms |
13464 KB |
Output is correct |
37 |
Correct |
147 ms |
13464 KB |
Output is correct |
38 |
Correct |
122 ms |
13464 KB |
Output is correct |
39 |
Correct |
149 ms |
13464 KB |
Output is correct |
40 |
Correct |
152 ms |
13464 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 |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
4 ms |
712 KB |
Output is correct |
8 |
Correct |
3 ms |
712 KB |
Output is correct |
9 |
Correct |
2 ms |
712 KB |
Output is correct |
10 |
Correct |
3 ms |
712 KB |
Output is correct |
11 |
Correct |
251 ms |
5216 KB |
Output is correct |
12 |
Correct |
340 ms |
5216 KB |
Output is correct |
13 |
Correct |
326 ms |
5216 KB |
Output is correct |
14 |
Correct |
388 ms |
5216 KB |
Output is correct |
15 |
Correct |
346 ms |
5612 KB |
Output is correct |
16 |
Correct |
292 ms |
5612 KB |
Output is correct |
17 |
Correct |
286 ms |
5620 KB |
Output is correct |
18 |
Correct |
194 ms |
7452 KB |
Output is correct |
19 |
Correct |
239 ms |
7452 KB |
Output is correct |
20 |
Correct |
248 ms |
7452 KB |
Output is correct |
21 |
Correct |
328 ms |
7452 KB |
Output is correct |
22 |
Correct |
319 ms |
7452 KB |
Output is correct |
23 |
Correct |
377 ms |
7452 KB |
Output is correct |
24 |
Correct |
308 ms |
7452 KB |
Output is correct |
25 |
Correct |
286 ms |
7892 KB |
Output is correct |
26 |
Correct |
372 ms |
7892 KB |
Output is correct |
27 |
Correct |
339 ms |
7892 KB |
Output is correct |
28 |
Correct |
207 ms |
9048 KB |
Output is correct |
29 |
Correct |
297 ms |
9048 KB |
Output is correct |
30 |
Correct |
305 ms |
9048 KB |
Output is correct |
31 |
Correct |
312 ms |
9048 KB |
Output is correct |
32 |
Correct |
420 ms |
9048 KB |
Output is correct |
33 |
Correct |
326 ms |
9048 KB |
Output is correct |
34 |
Correct |
375 ms |
9048 KB |
Output is correct |
35 |
Correct |
340 ms |
9048 KB |
Output is correct |
36 |
Correct |
232 ms |
9048 KB |
Output is correct |
37 |
Correct |
261 ms |
9048 KB |
Output is correct |
38 |
Correct |
254 ms |
9048 KB |
Output is correct |
39 |
Correct |
326 ms |
9048 KB |
Output is correct |
40 |
Correct |
334 ms |
9048 KB |
Output is correct |
41 |
Correct |
122 ms |
13108 KB |
Output is correct |
42 |
Correct |
128 ms |
13108 KB |
Output is correct |
43 |
Correct |
132 ms |
13108 KB |
Output is correct |
44 |
Correct |
194 ms |
13108 KB |
Output is correct |
45 |
Correct |
170 ms |
13108 KB |
Output is correct |
46 |
Correct |
162 ms |
13108 KB |
Output is correct |
47 |
Correct |
124 ms |
13108 KB |
Output is correct |
48 |
Correct |
101 ms |
13148 KB |
Output is correct |
49 |
Correct |
120 ms |
13148 KB |
Output is correct |
50 |
Correct |
122 ms |
13148 KB |
Output is correct |
51 |
Correct |
130 ms |
13192 KB |
Output is correct |
52 |
Correct |
133 ms |
13192 KB |
Output is correct |
53 |
Correct |
111 ms |
13192 KB |
Output is correct |
54 |
Correct |
137 ms |
13192 KB |
Output is correct |
55 |
Correct |
153 ms |
13192 KB |
Output is correct |
56 |
Correct |
99 ms |
13244 KB |
Output is correct |
57 |
Correct |
107 ms |
13284 KB |
Output is correct |
58 |
Correct |
139 ms |
13292 KB |
Output is correct |
59 |
Correct |
129 ms |
13312 KB |
Output is correct |
60 |
Correct |
122 ms |
13412 KB |
Output is correct |
61 |
Correct |
119 ms |
13412 KB |
Output is correct |
62 |
Correct |
131 ms |
13412 KB |
Output is correct |
63 |
Correct |
165 ms |
13412 KB |
Output is correct |
64 |
Correct |
94 ms |
13412 KB |
Output is correct |
65 |
Correct |
127 ms |
13464 KB |
Output is correct |
66 |
Correct |
179 ms |
13464 KB |
Output is correct |
67 |
Correct |
147 ms |
13464 KB |
Output is correct |
68 |
Correct |
122 ms |
13464 KB |
Output is correct |
69 |
Correct |
149 ms |
13464 KB |
Output is correct |
70 |
Correct |
152 ms |
13464 KB |
Output is correct |
71 |
Correct |
717 ms |
18148 KB |
Output is correct |
72 |
Correct |
562 ms |
18748 KB |
Output is correct |
73 |
Correct |
627 ms |
18748 KB |
Output is correct |
74 |
Correct |
988 ms |
18748 KB |
Output is correct |
75 |
Correct |
609 ms |
19804 KB |
Output is correct |
76 |
Correct |
1224 ms |
19804 KB |
Output is correct |
77 |
Correct |
1026 ms |
19804 KB |
Output is correct |
78 |
Correct |
508 ms |
43088 KB |
Output is correct |
79 |
Correct |
588 ms |
43088 KB |
Output is correct |
80 |
Correct |
609 ms |
62124 KB |
Output is correct |
81 |
Runtime error |
978 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. |
82 |
Halted |
0 ms |
0 KB |
- |