#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)
~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
242 ms |
5048 KB |
Output is correct |
12 |
Correct |
257 ms |
5080 KB |
Output is correct |
13 |
Correct |
293 ms |
5080 KB |
Output is correct |
14 |
Correct |
274 ms |
5080 KB |
Output is correct |
15 |
Correct |
263 ms |
5620 KB |
Output is correct |
16 |
Correct |
294 ms |
5620 KB |
Output is correct |
17 |
Correct |
296 ms |
5624 KB |
Output is correct |
18 |
Correct |
199 ms |
7316 KB |
Output is correct |
19 |
Correct |
234 ms |
7316 KB |
Output is correct |
20 |
Correct |
298 ms |
7316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
242 ms |
5048 KB |
Output is correct |
12 |
Correct |
257 ms |
5080 KB |
Output is correct |
13 |
Correct |
293 ms |
5080 KB |
Output is correct |
14 |
Correct |
274 ms |
5080 KB |
Output is correct |
15 |
Correct |
263 ms |
5620 KB |
Output is correct |
16 |
Correct |
294 ms |
5620 KB |
Output is correct |
17 |
Correct |
296 ms |
5624 KB |
Output is correct |
18 |
Correct |
199 ms |
7316 KB |
Output is correct |
19 |
Correct |
234 ms |
7316 KB |
Output is correct |
20 |
Correct |
298 ms |
7316 KB |
Output is correct |
21 |
Correct |
287 ms |
7316 KB |
Output is correct |
22 |
Correct |
332 ms |
7316 KB |
Output is correct |
23 |
Correct |
353 ms |
7316 KB |
Output is correct |
24 |
Correct |
324 ms |
7316 KB |
Output is correct |
25 |
Correct |
369 ms |
7656 KB |
Output is correct |
26 |
Correct |
483 ms |
7656 KB |
Output is correct |
27 |
Correct |
347 ms |
7656 KB |
Output is correct |
28 |
Correct |
223 ms |
8932 KB |
Output is correct |
29 |
Correct |
309 ms |
8932 KB |
Output is correct |
30 |
Correct |
315 ms |
8932 KB |
Output is correct |
31 |
Correct |
361 ms |
8932 KB |
Output is correct |
32 |
Correct |
450 ms |
8932 KB |
Output is correct |
33 |
Correct |
335 ms |
8932 KB |
Output is correct |
34 |
Correct |
360 ms |
8932 KB |
Output is correct |
35 |
Correct |
362 ms |
8932 KB |
Output is correct |
36 |
Correct |
217 ms |
8932 KB |
Output is correct |
37 |
Correct |
314 ms |
8932 KB |
Output is correct |
38 |
Correct |
274 ms |
8932 KB |
Output is correct |
39 |
Correct |
337 ms |
8932 KB |
Output is correct |
40 |
Correct |
331 ms |
8932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
114 ms |
13096 KB |
Output is correct |
12 |
Correct |
114 ms |
13096 KB |
Output is correct |
13 |
Correct |
123 ms |
13096 KB |
Output is correct |
14 |
Correct |
218 ms |
13096 KB |
Output is correct |
15 |
Correct |
116 ms |
13096 KB |
Output is correct |
16 |
Correct |
166 ms |
13096 KB |
Output is correct |
17 |
Correct |
165 ms |
13096 KB |
Output is correct |
18 |
Correct |
115 ms |
13136 KB |
Output is correct |
19 |
Correct |
152 ms |
13136 KB |
Output is correct |
20 |
Correct |
133 ms |
13136 KB |
Output is correct |
21 |
Correct |
134 ms |
13136 KB |
Output is correct |
22 |
Correct |
154 ms |
13136 KB |
Output is correct |
23 |
Correct |
120 ms |
13136 KB |
Output is correct |
24 |
Correct |
138 ms |
13136 KB |
Output is correct |
25 |
Correct |
146 ms |
13136 KB |
Output is correct |
26 |
Correct |
109 ms |
13144 KB |
Output is correct |
27 |
Correct |
113 ms |
13192 KB |
Output is correct |
28 |
Correct |
114 ms |
13192 KB |
Output is correct |
29 |
Correct |
126 ms |
13316 KB |
Output is correct |
30 |
Correct |
114 ms |
13316 KB |
Output is correct |
31 |
Correct |
115 ms |
13316 KB |
Output is correct |
32 |
Correct |
148 ms |
13316 KB |
Output is correct |
33 |
Correct |
145 ms |
13316 KB |
Output is correct |
34 |
Correct |
101 ms |
13316 KB |
Output is correct |
35 |
Correct |
136 ms |
13316 KB |
Output is correct |
36 |
Correct |
156 ms |
13316 KB |
Output is correct |
37 |
Correct |
134 ms |
13320 KB |
Output is correct |
38 |
Correct |
152 ms |
13320 KB |
Output is correct |
39 |
Correct |
134 ms |
13320 KB |
Output is correct |
40 |
Correct |
136 ms |
13320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
636 KB |
Output is correct |
7 |
Correct |
2 ms |
636 KB |
Output is correct |
8 |
Correct |
2 ms |
636 KB |
Output is correct |
9 |
Correct |
2 ms |
636 KB |
Output is correct |
10 |
Correct |
2 ms |
636 KB |
Output is correct |
11 |
Correct |
242 ms |
5048 KB |
Output is correct |
12 |
Correct |
257 ms |
5080 KB |
Output is correct |
13 |
Correct |
293 ms |
5080 KB |
Output is correct |
14 |
Correct |
274 ms |
5080 KB |
Output is correct |
15 |
Correct |
263 ms |
5620 KB |
Output is correct |
16 |
Correct |
294 ms |
5620 KB |
Output is correct |
17 |
Correct |
296 ms |
5624 KB |
Output is correct |
18 |
Correct |
199 ms |
7316 KB |
Output is correct |
19 |
Correct |
234 ms |
7316 KB |
Output is correct |
20 |
Correct |
298 ms |
7316 KB |
Output is correct |
21 |
Correct |
287 ms |
7316 KB |
Output is correct |
22 |
Correct |
332 ms |
7316 KB |
Output is correct |
23 |
Correct |
353 ms |
7316 KB |
Output is correct |
24 |
Correct |
324 ms |
7316 KB |
Output is correct |
25 |
Correct |
369 ms |
7656 KB |
Output is correct |
26 |
Correct |
483 ms |
7656 KB |
Output is correct |
27 |
Correct |
347 ms |
7656 KB |
Output is correct |
28 |
Correct |
223 ms |
8932 KB |
Output is correct |
29 |
Correct |
309 ms |
8932 KB |
Output is correct |
30 |
Correct |
315 ms |
8932 KB |
Output is correct |
31 |
Correct |
361 ms |
8932 KB |
Output is correct |
32 |
Correct |
450 ms |
8932 KB |
Output is correct |
33 |
Correct |
335 ms |
8932 KB |
Output is correct |
34 |
Correct |
360 ms |
8932 KB |
Output is correct |
35 |
Correct |
362 ms |
8932 KB |
Output is correct |
36 |
Correct |
217 ms |
8932 KB |
Output is correct |
37 |
Correct |
314 ms |
8932 KB |
Output is correct |
38 |
Correct |
274 ms |
8932 KB |
Output is correct |
39 |
Correct |
337 ms |
8932 KB |
Output is correct |
40 |
Correct |
331 ms |
8932 KB |
Output is correct |
41 |
Correct |
114 ms |
13096 KB |
Output is correct |
42 |
Correct |
114 ms |
13096 KB |
Output is correct |
43 |
Correct |
123 ms |
13096 KB |
Output is correct |
44 |
Correct |
218 ms |
13096 KB |
Output is correct |
45 |
Correct |
116 ms |
13096 KB |
Output is correct |
46 |
Correct |
166 ms |
13096 KB |
Output is correct |
47 |
Correct |
165 ms |
13096 KB |
Output is correct |
48 |
Correct |
115 ms |
13136 KB |
Output is correct |
49 |
Correct |
152 ms |
13136 KB |
Output is correct |
50 |
Correct |
133 ms |
13136 KB |
Output is correct |
51 |
Correct |
134 ms |
13136 KB |
Output is correct |
52 |
Correct |
154 ms |
13136 KB |
Output is correct |
53 |
Correct |
120 ms |
13136 KB |
Output is correct |
54 |
Correct |
138 ms |
13136 KB |
Output is correct |
55 |
Correct |
146 ms |
13136 KB |
Output is correct |
56 |
Correct |
109 ms |
13144 KB |
Output is correct |
57 |
Correct |
113 ms |
13192 KB |
Output is correct |
58 |
Correct |
114 ms |
13192 KB |
Output is correct |
59 |
Correct |
126 ms |
13316 KB |
Output is correct |
60 |
Correct |
114 ms |
13316 KB |
Output is correct |
61 |
Correct |
115 ms |
13316 KB |
Output is correct |
62 |
Correct |
148 ms |
13316 KB |
Output is correct |
63 |
Correct |
145 ms |
13316 KB |
Output is correct |
64 |
Correct |
101 ms |
13316 KB |
Output is correct |
65 |
Correct |
136 ms |
13316 KB |
Output is correct |
66 |
Correct |
156 ms |
13316 KB |
Output is correct |
67 |
Correct |
134 ms |
13320 KB |
Output is correct |
68 |
Correct |
152 ms |
13320 KB |
Output is correct |
69 |
Correct |
134 ms |
13320 KB |
Output is correct |
70 |
Correct |
136 ms |
13320 KB |
Output is correct |
71 |
Correct |
631 ms |
17984 KB |
Output is correct |
72 |
Correct |
781 ms |
18812 KB |
Output is correct |
73 |
Correct |
969 ms |
18812 KB |
Output is correct |
74 |
Correct |
1660 ms |
18812 KB |
Output is correct |
75 |
Correct |
655 ms |
19632 KB |
Output is correct |
76 |
Correct |
1423 ms |
19632 KB |
Output is correct |
77 |
Correct |
1103 ms |
19632 KB |
Output is correct |
78 |
Correct |
407 ms |
34676 KB |
Output is correct |
79 |
Correct |
536 ms |
34676 KB |
Output is correct |
80 |
Correct |
684 ms |
34676 KB |
Output is correct |
81 |
Correct |
1130 ms |
34676 KB |
Output is correct |
82 |
Correct |
1617 ms |
52712 KB |
Output is correct |
83 |
Runtime error |
601 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. |
84 |
Halted |
0 ms |
0 KB |
- |