#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 |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
792 KB |
Output is correct |
10 |
Correct |
4 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
792 KB |
Output is correct |
10 |
Correct |
4 ms |
792 KB |
Output is correct |
11 |
Correct |
258 ms |
4932 KB |
Output is correct |
12 |
Correct |
255 ms |
4932 KB |
Output is correct |
13 |
Correct |
272 ms |
4932 KB |
Output is correct |
14 |
Correct |
291 ms |
4932 KB |
Output is correct |
15 |
Correct |
300 ms |
5044 KB |
Output is correct |
16 |
Correct |
326 ms |
5044 KB |
Output is correct |
17 |
Correct |
364 ms |
5044 KB |
Output is correct |
18 |
Correct |
188 ms |
5912 KB |
Output is correct |
19 |
Correct |
245 ms |
5912 KB |
Output is correct |
20 |
Correct |
273 ms |
5912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
792 KB |
Output is correct |
10 |
Correct |
4 ms |
792 KB |
Output is correct |
11 |
Correct |
258 ms |
4932 KB |
Output is correct |
12 |
Correct |
255 ms |
4932 KB |
Output is correct |
13 |
Correct |
272 ms |
4932 KB |
Output is correct |
14 |
Correct |
291 ms |
4932 KB |
Output is correct |
15 |
Correct |
300 ms |
5044 KB |
Output is correct |
16 |
Correct |
326 ms |
5044 KB |
Output is correct |
17 |
Correct |
364 ms |
5044 KB |
Output is correct |
18 |
Correct |
188 ms |
5912 KB |
Output is correct |
19 |
Correct |
245 ms |
5912 KB |
Output is correct |
20 |
Correct |
273 ms |
5912 KB |
Output is correct |
21 |
Correct |
302 ms |
5912 KB |
Output is correct |
22 |
Correct |
306 ms |
5912 KB |
Output is correct |
23 |
Correct |
332 ms |
5912 KB |
Output is correct |
24 |
Correct |
315 ms |
5912 KB |
Output is correct |
25 |
Correct |
336 ms |
6040 KB |
Output is correct |
26 |
Correct |
388 ms |
6040 KB |
Output is correct |
27 |
Correct |
431 ms |
6040 KB |
Output is correct |
28 |
Correct |
232 ms |
8876 KB |
Output is correct |
29 |
Correct |
324 ms |
8876 KB |
Output is correct |
30 |
Correct |
287 ms |
8876 KB |
Output is correct |
31 |
Correct |
312 ms |
8876 KB |
Output is correct |
32 |
Correct |
501 ms |
8876 KB |
Output is correct |
33 |
Correct |
299 ms |
8876 KB |
Output is correct |
34 |
Correct |
349 ms |
8876 KB |
Output is correct |
35 |
Correct |
370 ms |
8876 KB |
Output is correct |
36 |
Correct |
281 ms |
9312 KB |
Output is correct |
37 |
Correct |
250 ms |
11056 KB |
Output is correct |
38 |
Correct |
271 ms |
11056 KB |
Output is correct |
39 |
Correct |
323 ms |
11056 KB |
Output is correct |
40 |
Correct |
357 ms |
11056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
792 KB |
Output is correct |
10 |
Correct |
4 ms |
792 KB |
Output is correct |
11 |
Correct |
119 ms |
16856 KB |
Output is correct |
12 |
Correct |
104 ms |
16960 KB |
Output is correct |
13 |
Correct |
122 ms |
16960 KB |
Output is correct |
14 |
Correct |
139 ms |
16984 KB |
Output is correct |
15 |
Correct |
156 ms |
16984 KB |
Output is correct |
16 |
Correct |
142 ms |
16984 KB |
Output is correct |
17 |
Correct |
137 ms |
16984 KB |
Output is correct |
18 |
Correct |
104 ms |
17092 KB |
Output is correct |
19 |
Correct |
104 ms |
17092 KB |
Output is correct |
20 |
Correct |
117 ms |
17092 KB |
Output is correct |
21 |
Correct |
131 ms |
17092 KB |
Output is correct |
22 |
Correct |
146 ms |
19016 KB |
Output is correct |
23 |
Correct |
128 ms |
20952 KB |
Output is correct |
24 |
Correct |
126 ms |
23016 KB |
Output is correct |
25 |
Correct |
129 ms |
25116 KB |
Output is correct |
26 |
Correct |
117 ms |
27012 KB |
Output is correct |
27 |
Correct |
118 ms |
29208 KB |
Output is correct |
28 |
Correct |
121 ms |
31240 KB |
Output is correct |
29 |
Correct |
127 ms |
33436 KB |
Output is correct |
30 |
Correct |
134 ms |
35504 KB |
Output is correct |
31 |
Correct |
104 ms |
37428 KB |
Output is correct |
32 |
Correct |
169 ms |
39564 KB |
Output is correct |
33 |
Correct |
198 ms |
41648 KB |
Output is correct |
34 |
Correct |
132 ms |
43488 KB |
Output is correct |
35 |
Correct |
150 ms |
45688 KB |
Output is correct |
36 |
Correct |
127 ms |
47932 KB |
Output is correct |
37 |
Correct |
126 ms |
49804 KB |
Output is correct |
38 |
Correct |
138 ms |
51856 KB |
Output is correct |
39 |
Correct |
134 ms |
54052 KB |
Output is correct |
40 |
Correct |
144 ms |
56084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
496 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
628 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
792 KB |
Output is correct |
10 |
Correct |
4 ms |
792 KB |
Output is correct |
11 |
Correct |
258 ms |
4932 KB |
Output is correct |
12 |
Correct |
255 ms |
4932 KB |
Output is correct |
13 |
Correct |
272 ms |
4932 KB |
Output is correct |
14 |
Correct |
291 ms |
4932 KB |
Output is correct |
15 |
Correct |
300 ms |
5044 KB |
Output is correct |
16 |
Correct |
326 ms |
5044 KB |
Output is correct |
17 |
Correct |
364 ms |
5044 KB |
Output is correct |
18 |
Correct |
188 ms |
5912 KB |
Output is correct |
19 |
Correct |
245 ms |
5912 KB |
Output is correct |
20 |
Correct |
273 ms |
5912 KB |
Output is correct |
21 |
Correct |
302 ms |
5912 KB |
Output is correct |
22 |
Correct |
306 ms |
5912 KB |
Output is correct |
23 |
Correct |
332 ms |
5912 KB |
Output is correct |
24 |
Correct |
315 ms |
5912 KB |
Output is correct |
25 |
Correct |
336 ms |
6040 KB |
Output is correct |
26 |
Correct |
388 ms |
6040 KB |
Output is correct |
27 |
Correct |
431 ms |
6040 KB |
Output is correct |
28 |
Correct |
232 ms |
8876 KB |
Output is correct |
29 |
Correct |
324 ms |
8876 KB |
Output is correct |
30 |
Correct |
287 ms |
8876 KB |
Output is correct |
31 |
Correct |
312 ms |
8876 KB |
Output is correct |
32 |
Correct |
501 ms |
8876 KB |
Output is correct |
33 |
Correct |
299 ms |
8876 KB |
Output is correct |
34 |
Correct |
349 ms |
8876 KB |
Output is correct |
35 |
Correct |
370 ms |
8876 KB |
Output is correct |
36 |
Correct |
281 ms |
9312 KB |
Output is correct |
37 |
Correct |
250 ms |
11056 KB |
Output is correct |
38 |
Correct |
271 ms |
11056 KB |
Output is correct |
39 |
Correct |
323 ms |
11056 KB |
Output is correct |
40 |
Correct |
357 ms |
11056 KB |
Output is correct |
41 |
Correct |
119 ms |
16856 KB |
Output is correct |
42 |
Correct |
104 ms |
16960 KB |
Output is correct |
43 |
Correct |
122 ms |
16960 KB |
Output is correct |
44 |
Correct |
139 ms |
16984 KB |
Output is correct |
45 |
Correct |
156 ms |
16984 KB |
Output is correct |
46 |
Correct |
142 ms |
16984 KB |
Output is correct |
47 |
Correct |
137 ms |
16984 KB |
Output is correct |
48 |
Correct |
104 ms |
17092 KB |
Output is correct |
49 |
Correct |
104 ms |
17092 KB |
Output is correct |
50 |
Correct |
117 ms |
17092 KB |
Output is correct |
51 |
Correct |
131 ms |
17092 KB |
Output is correct |
52 |
Correct |
146 ms |
19016 KB |
Output is correct |
53 |
Correct |
128 ms |
20952 KB |
Output is correct |
54 |
Correct |
126 ms |
23016 KB |
Output is correct |
55 |
Correct |
129 ms |
25116 KB |
Output is correct |
56 |
Correct |
117 ms |
27012 KB |
Output is correct |
57 |
Correct |
118 ms |
29208 KB |
Output is correct |
58 |
Correct |
121 ms |
31240 KB |
Output is correct |
59 |
Correct |
127 ms |
33436 KB |
Output is correct |
60 |
Correct |
134 ms |
35504 KB |
Output is correct |
61 |
Correct |
104 ms |
37428 KB |
Output is correct |
62 |
Correct |
169 ms |
39564 KB |
Output is correct |
63 |
Correct |
198 ms |
41648 KB |
Output is correct |
64 |
Correct |
132 ms |
43488 KB |
Output is correct |
65 |
Correct |
150 ms |
45688 KB |
Output is correct |
66 |
Correct |
127 ms |
47932 KB |
Output is correct |
67 |
Correct |
126 ms |
49804 KB |
Output is correct |
68 |
Correct |
138 ms |
51856 KB |
Output is correct |
69 |
Correct |
134 ms |
54052 KB |
Output is correct |
70 |
Correct |
144 ms |
56084 KB |
Output is correct |
71 |
Runtime error |
638 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. |
72 |
Halted |
0 ms |
0 KB |
- |