#include <bits/stdc++.h>
using namespace std;
#define getchar_unlocked getchar
#define putchar_unlocked putchar
inline int in() {
int result = 0;
char ch = getchar_unlocked();
while(true) {
if(ch >= '0' && ch <= '9')
break;
ch = getchar_unlocked();
}
result = ch-'0';
while(true) {
ch = getchar_unlocked();
if (ch < '0' || ch > '9')
break;
result = result*10 + (ch - '0');
}
return result;
}
inline void out(int x) {
if(!x) {
putchar_unlocked('0');
return;
}
int rev=x, c=0;
while(!(rev%10)) {
++c;
rev/=10;
}
rev=0;
while(x) {
rev=rev*10+x%10;
x/=10;
}
while(rev) {
putchar_unlocked(rev%10+'0');
rev/=10;
}
while(c--)
putchar_unlocked('0');
}
const int mxL=20, mxQ=1e6;
int l, q, dp[2][1<<mxL];
char s[1<<mxL];
int main() {
l=in(), q=in();
for(int i=0; i<1<<l; ++i)
while(s[i]<'0'||s[i]>'9')
s[i]=getchar_unlocked();
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--) {
int na=0, nb=0, nc=0, ma=0, mb=0, mc=0, ans=0;
for(int i=0; i<l; ++i) {
char c=getchar_unlocked();
if(c=='0') {
++na;
ma|=1<<(l-1-i);
} else if(c=='1') {
++nb;
mb|=1<<(l-1-i);
} else if(c=='?') {
++nc;
mc|=1<<(l-1-i);
} else
--i;
}
if(na<nc||nb<nc) {
bool sw=0;
if(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;
}
}
out(ans);
putchar_unlocked('\n');
}
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:61:12: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
if(i>>k&1^j)
~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
3 ms |
448 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
476 KB |
Output is correct |
7 |
Correct |
3 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
560 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
3 ms |
448 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
476 KB |
Output is correct |
7 |
Correct |
3 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
560 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
293 ms |
7568 KB |
Output is correct |
12 |
Correct |
239 ms |
7568 KB |
Output is correct |
13 |
Correct |
271 ms |
7568 KB |
Output is correct |
14 |
Correct |
251 ms |
7568 KB |
Output is correct |
15 |
Correct |
253 ms |
7948 KB |
Output is correct |
16 |
Correct |
279 ms |
7948 KB |
Output is correct |
17 |
Correct |
264 ms |
7948 KB |
Output is correct |
18 |
Correct |
236 ms |
10424 KB |
Output is correct |
19 |
Correct |
203 ms |
10424 KB |
Output is correct |
20 |
Correct |
278 ms |
10424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
3 ms |
448 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
476 KB |
Output is correct |
7 |
Correct |
3 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
560 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
293 ms |
7568 KB |
Output is correct |
12 |
Correct |
239 ms |
7568 KB |
Output is correct |
13 |
Correct |
271 ms |
7568 KB |
Output is correct |
14 |
Correct |
251 ms |
7568 KB |
Output is correct |
15 |
Correct |
253 ms |
7948 KB |
Output is correct |
16 |
Correct |
279 ms |
7948 KB |
Output is correct |
17 |
Correct |
264 ms |
7948 KB |
Output is correct |
18 |
Correct |
236 ms |
10424 KB |
Output is correct |
19 |
Correct |
203 ms |
10424 KB |
Output is correct |
20 |
Correct |
278 ms |
10424 KB |
Output is correct |
21 |
Correct |
324 ms |
10424 KB |
Output is correct |
22 |
Correct |
289 ms |
10424 KB |
Output is correct |
23 |
Correct |
363 ms |
10424 KB |
Output is correct |
24 |
Correct |
359 ms |
10424 KB |
Output is correct |
25 |
Correct |
331 ms |
10460 KB |
Output is correct |
26 |
Correct |
346 ms |
10460 KB |
Output is correct |
27 |
Correct |
352 ms |
10460 KB |
Output is correct |
28 |
Correct |
292 ms |
13320 KB |
Output is correct |
29 |
Correct |
338 ms |
13320 KB |
Output is correct |
30 |
Correct |
321 ms |
13320 KB |
Output is correct |
31 |
Correct |
388 ms |
13320 KB |
Output is correct |
32 |
Correct |
419 ms |
13320 KB |
Output is correct |
33 |
Correct |
319 ms |
13320 KB |
Output is correct |
34 |
Correct |
339 ms |
13320 KB |
Output is correct |
35 |
Correct |
353 ms |
13320 KB |
Output is correct |
36 |
Correct |
200 ms |
13320 KB |
Output is correct |
37 |
Correct |
283 ms |
13320 KB |
Output is correct |
38 |
Correct |
257 ms |
13320 KB |
Output is correct |
39 |
Correct |
334 ms |
13320 KB |
Output is correct |
40 |
Correct |
334 ms |
13320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
3 ms |
448 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
476 KB |
Output is correct |
7 |
Correct |
3 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
560 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
143 ms |
17964 KB |
Output is correct |
12 |
Correct |
165 ms |
17964 KB |
Output is correct |
13 |
Correct |
154 ms |
17964 KB |
Output is correct |
14 |
Correct |
159 ms |
17976 KB |
Output is correct |
15 |
Correct |
139 ms |
18248 KB |
Output is correct |
16 |
Correct |
172 ms |
18248 KB |
Output is correct |
17 |
Correct |
142 ms |
18248 KB |
Output is correct |
18 |
Correct |
104 ms |
18248 KB |
Output is correct |
19 |
Correct |
122 ms |
18248 KB |
Output is correct |
20 |
Correct |
133 ms |
18248 KB |
Output is correct |
21 |
Correct |
133 ms |
18248 KB |
Output is correct |
22 |
Correct |
171 ms |
18248 KB |
Output is correct |
23 |
Correct |
107 ms |
18248 KB |
Output is correct |
24 |
Correct |
129 ms |
18248 KB |
Output is correct |
25 |
Correct |
141 ms |
18248 KB |
Output is correct |
26 |
Correct |
124 ms |
18248 KB |
Output is correct |
27 |
Correct |
126 ms |
18248 KB |
Output is correct |
28 |
Correct |
113 ms |
18248 KB |
Output is correct |
29 |
Correct |
137 ms |
18248 KB |
Output is correct |
30 |
Correct |
142 ms |
18248 KB |
Output is correct |
31 |
Correct |
114 ms |
18248 KB |
Output is correct |
32 |
Correct |
193 ms |
18248 KB |
Output is correct |
33 |
Correct |
166 ms |
18248 KB |
Output is correct |
34 |
Correct |
147 ms |
18248 KB |
Output is correct |
35 |
Correct |
142 ms |
18248 KB |
Output is correct |
36 |
Correct |
165 ms |
18248 KB |
Output is correct |
37 |
Correct |
154 ms |
18248 KB |
Output is correct |
38 |
Correct |
182 ms |
18248 KB |
Output is correct |
39 |
Correct |
135 ms |
18248 KB |
Output is correct |
40 |
Correct |
146 ms |
18248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
448 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
3 ms |
448 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
3 ms |
476 KB |
Output is correct |
7 |
Correct |
3 ms |
548 KB |
Output is correct |
8 |
Correct |
3 ms |
560 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
293 ms |
7568 KB |
Output is correct |
12 |
Correct |
239 ms |
7568 KB |
Output is correct |
13 |
Correct |
271 ms |
7568 KB |
Output is correct |
14 |
Correct |
251 ms |
7568 KB |
Output is correct |
15 |
Correct |
253 ms |
7948 KB |
Output is correct |
16 |
Correct |
279 ms |
7948 KB |
Output is correct |
17 |
Correct |
264 ms |
7948 KB |
Output is correct |
18 |
Correct |
236 ms |
10424 KB |
Output is correct |
19 |
Correct |
203 ms |
10424 KB |
Output is correct |
20 |
Correct |
278 ms |
10424 KB |
Output is correct |
21 |
Correct |
324 ms |
10424 KB |
Output is correct |
22 |
Correct |
289 ms |
10424 KB |
Output is correct |
23 |
Correct |
363 ms |
10424 KB |
Output is correct |
24 |
Correct |
359 ms |
10424 KB |
Output is correct |
25 |
Correct |
331 ms |
10460 KB |
Output is correct |
26 |
Correct |
346 ms |
10460 KB |
Output is correct |
27 |
Correct |
352 ms |
10460 KB |
Output is correct |
28 |
Correct |
292 ms |
13320 KB |
Output is correct |
29 |
Correct |
338 ms |
13320 KB |
Output is correct |
30 |
Correct |
321 ms |
13320 KB |
Output is correct |
31 |
Correct |
388 ms |
13320 KB |
Output is correct |
32 |
Correct |
419 ms |
13320 KB |
Output is correct |
33 |
Correct |
319 ms |
13320 KB |
Output is correct |
34 |
Correct |
339 ms |
13320 KB |
Output is correct |
35 |
Correct |
353 ms |
13320 KB |
Output is correct |
36 |
Correct |
200 ms |
13320 KB |
Output is correct |
37 |
Correct |
283 ms |
13320 KB |
Output is correct |
38 |
Correct |
257 ms |
13320 KB |
Output is correct |
39 |
Correct |
334 ms |
13320 KB |
Output is correct |
40 |
Correct |
334 ms |
13320 KB |
Output is correct |
41 |
Correct |
143 ms |
17964 KB |
Output is correct |
42 |
Correct |
165 ms |
17964 KB |
Output is correct |
43 |
Correct |
154 ms |
17964 KB |
Output is correct |
44 |
Correct |
159 ms |
17976 KB |
Output is correct |
45 |
Correct |
139 ms |
18248 KB |
Output is correct |
46 |
Correct |
172 ms |
18248 KB |
Output is correct |
47 |
Correct |
142 ms |
18248 KB |
Output is correct |
48 |
Correct |
104 ms |
18248 KB |
Output is correct |
49 |
Correct |
122 ms |
18248 KB |
Output is correct |
50 |
Correct |
133 ms |
18248 KB |
Output is correct |
51 |
Correct |
133 ms |
18248 KB |
Output is correct |
52 |
Correct |
171 ms |
18248 KB |
Output is correct |
53 |
Correct |
107 ms |
18248 KB |
Output is correct |
54 |
Correct |
129 ms |
18248 KB |
Output is correct |
55 |
Correct |
141 ms |
18248 KB |
Output is correct |
56 |
Correct |
124 ms |
18248 KB |
Output is correct |
57 |
Correct |
126 ms |
18248 KB |
Output is correct |
58 |
Correct |
113 ms |
18248 KB |
Output is correct |
59 |
Correct |
137 ms |
18248 KB |
Output is correct |
60 |
Correct |
142 ms |
18248 KB |
Output is correct |
61 |
Correct |
114 ms |
18248 KB |
Output is correct |
62 |
Correct |
193 ms |
18248 KB |
Output is correct |
63 |
Correct |
166 ms |
18248 KB |
Output is correct |
64 |
Correct |
147 ms |
18248 KB |
Output is correct |
65 |
Correct |
142 ms |
18248 KB |
Output is correct |
66 |
Correct |
165 ms |
18248 KB |
Output is correct |
67 |
Correct |
154 ms |
18248 KB |
Output is correct |
68 |
Correct |
182 ms |
18248 KB |
Output is correct |
69 |
Correct |
135 ms |
18248 KB |
Output is correct |
70 |
Correct |
146 ms |
18248 KB |
Output is correct |
71 |
Correct |
688 ms |
22700 KB |
Output is correct |
72 |
Correct |
651 ms |
23708 KB |
Output is correct |
73 |
Correct |
748 ms |
23708 KB |
Output is correct |
74 |
Correct |
1363 ms |
23708 KB |
Output is correct |
75 |
Correct |
666 ms |
24624 KB |
Output is correct |
76 |
Correct |
1570 ms |
24624 KB |
Output is correct |
77 |
Correct |
1188 ms |
24624 KB |
Output is correct |
78 |
Correct |
478 ms |
26672 KB |
Output is correct |
79 |
Correct |
514 ms |
26672 KB |
Output is correct |
80 |
Correct |
709 ms |
26672 KB |
Output is correct |
81 |
Correct |
1124 ms |
26672 KB |
Output is correct |
82 |
Correct |
1861 ms |
26672 KB |
Output is correct |
83 |
Correct |
568 ms |
26672 KB |
Output is correct |
84 |
Correct |
1061 ms |
26672 KB |
Output is correct |
85 |
Correct |
1160 ms |
26672 KB |
Output is correct |
86 |
Correct |
359 ms |
26672 KB |
Output is correct |
87 |
Correct |
629 ms |
26672 KB |
Output is correct |
88 |
Correct |
530 ms |
26672 KB |
Output is correct |
89 |
Correct |
757 ms |
26672 KB |
Output is correct |
90 |
Correct |
662 ms |
26672 KB |
Output is correct |
91 |
Correct |
642 ms |
26672 KB |
Output is correct |
92 |
Correct |
1512 ms |
26672 KB |
Output is correct |
93 |
Correct |
1401 ms |
26672 KB |
Output is correct |
94 |
Correct |
338 ms |
26672 KB |
Output is correct |
95 |
Correct |
1099 ms |
26672 KB |
Output is correct |
96 |
Correct |
934 ms |
26672 KB |
Output is correct |
97 |
Correct |
948 ms |
26672 KB |
Output is correct |
98 |
Correct |
904 ms |
46292 KB |
Output is correct |
99 |
Runtime error |
1077 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. |
100 |
Halted |
0 ms |
0 KB |
- |