#include <bits/stdc++.h>
using namespace std;
int nd,n,d,d2,p3[13],dh[531441],pst[531441],a[1ll<<20],wg[1000000],wgg[1000000],mka[1000000],dp[531441],sq[1000000];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t,rr,i,k,w,mk;
string s;
cin>>nd>>t;
n=1ll<<nd;
d=min(nd,8);
d2=max(nd-8,0);
p3[0]=1;
for(i=1;i<=d2;i++)
{
p3[i]=p3[i-1]*3;
}
for(mk=0;mk<p3[d2];mk++)
{
w=0;
for(i=d2-1;i+1;i--)
{
k=mk/p3[i]%3;
if(k==2)
{
break;
}
w=w<<1|k;
}
dh[mk]=i;
if(dh[mk]==-1)
{
pst[mk]=w;
}
}
cin>>s;
for(i=0;i<n;i++)
{
a[i]=s[i]-'0';
}
for(rr=0;rr<t;rr++)
{
cin>>s;
wg[rr]=0;
wgg[rr]=0;
for(i=0;i<d;i++)
{
k=(s[i]=='1')+2*(s[i]=='?');
wg[rr]=wg[rr]<<1|k%2;
wgg[rr]=wgg[rr]<<1|k<2;
}
mka[rr]=0;
for(i=0;i<d2;i++)
{
k=(s[d+i]=='1')+2*(s[d+i]=='?');
mka[rr]=mka[rr]*3+k;
}
}
for(i=0;i<1ll<<d;i++)
{
for(mk=0;mk<p3[d2];mk++)
{
if(dh[mk]==-1)
{
dp[mk]=a[i<<d2|pst[mk]];
}
else
{
dp[mk]=dp[mk-p3[dh[mk]]*2]+dp[mk-p3[dh[mk]]];
}
}
for(rr=0;rr<t;rr++)
{
if((i&wgg[rr])==wg[rr])
{
sq[rr]+=dp[mka[rr]];
}
}
}
for(rr=0;rr<t;rr++)
{
cout<<sq[rr]<<"\n";
}
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:56:24: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
56 | wgg[rr]=wgg[rr]<<1|k<2;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
743 ms |
20084 KB |
Output is correct |
12 |
Correct |
859 ms |
19660 KB |
Output is correct |
13 |
Correct |
701 ms |
18936 KB |
Output is correct |
14 |
Correct |
728 ms |
19064 KB |
Output is correct |
15 |
Correct |
793 ms |
20040 KB |
Output is correct |
16 |
Correct |
671 ms |
19352 KB |
Output is correct |
17 |
Correct |
670 ms |
19276 KB |
Output is correct |
18 |
Correct |
493 ms |
20984 KB |
Output is correct |
19 |
Correct |
562 ms |
18040 KB |
Output is correct |
20 |
Correct |
811 ms |
19700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
743 ms |
20084 KB |
Output is correct |
12 |
Correct |
859 ms |
19660 KB |
Output is correct |
13 |
Correct |
701 ms |
18936 KB |
Output is correct |
14 |
Correct |
728 ms |
19064 KB |
Output is correct |
15 |
Correct |
793 ms |
20040 KB |
Output is correct |
16 |
Correct |
671 ms |
19352 KB |
Output is correct |
17 |
Correct |
670 ms |
19276 KB |
Output is correct |
18 |
Correct |
493 ms |
20984 KB |
Output is correct |
19 |
Correct |
562 ms |
18040 KB |
Output is correct |
20 |
Correct |
811 ms |
19700 KB |
Output is correct |
21 |
Correct |
808 ms |
20088 KB |
Output is correct |
22 |
Correct |
822 ms |
20344 KB |
Output is correct |
23 |
Correct |
712 ms |
19448 KB |
Output is correct |
24 |
Correct |
719 ms |
19064 KB |
Output is correct |
25 |
Correct |
887 ms |
21120 KB |
Output is correct |
26 |
Correct |
673 ms |
19536 KB |
Output is correct |
27 |
Correct |
670 ms |
19576 KB |
Output is correct |
28 |
Correct |
522 ms |
22024 KB |
Output is correct |
29 |
Correct |
570 ms |
18068 KB |
Output is correct |
30 |
Correct |
814 ms |
20348 KB |
Output is correct |
31 |
Correct |
669 ms |
20088 KB |
Output is correct |
32 |
Correct |
677 ms |
20128 KB |
Output is correct |
33 |
Correct |
616 ms |
19088 KB |
Output is correct |
34 |
Correct |
750 ms |
19172 KB |
Output is correct |
35 |
Correct |
671 ms |
19576 KB |
Output is correct |
36 |
Correct |
474 ms |
18200 KB |
Output is correct |
37 |
Correct |
731 ms |
20216 KB |
Output is correct |
38 |
Correct |
583 ms |
18108 KB |
Output is correct |
39 |
Correct |
698 ms |
19448 KB |
Output is correct |
40 |
Correct |
735 ms |
19068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
356 ms |
11144 KB |
Output is correct |
12 |
Correct |
358 ms |
11160 KB |
Output is correct |
13 |
Correct |
349 ms |
11156 KB |
Output is correct |
14 |
Correct |
357 ms |
11160 KB |
Output is correct |
15 |
Correct |
372 ms |
11288 KB |
Output is correct |
16 |
Correct |
348 ms |
11160 KB |
Output is correct |
17 |
Correct |
347 ms |
11164 KB |
Output is correct |
18 |
Correct |
332 ms |
11416 KB |
Output is correct |
19 |
Correct |
346 ms |
11008 KB |
Output is correct |
20 |
Correct |
350 ms |
11160 KB |
Output is correct |
21 |
Correct |
361 ms |
11144 KB |
Output is correct |
22 |
Correct |
345 ms |
11156 KB |
Output is correct |
23 |
Correct |
340 ms |
11292 KB |
Output is correct |
24 |
Correct |
344 ms |
11156 KB |
Output is correct |
25 |
Correct |
349 ms |
11160 KB |
Output is correct |
26 |
Correct |
328 ms |
11032 KB |
Output is correct |
27 |
Correct |
360 ms |
11208 KB |
Output is correct |
28 |
Correct |
340 ms |
11028 KB |
Output is correct |
29 |
Correct |
356 ms |
11160 KB |
Output is correct |
30 |
Correct |
343 ms |
11160 KB |
Output is correct |
31 |
Correct |
342 ms |
11160 KB |
Output is correct |
32 |
Correct |
356 ms |
11160 KB |
Output is correct |
33 |
Correct |
358 ms |
11164 KB |
Output is correct |
34 |
Correct |
336 ms |
11036 KB |
Output is correct |
35 |
Correct |
358 ms |
11164 KB |
Output is correct |
36 |
Correct |
355 ms |
11160 KB |
Output is correct |
37 |
Correct |
359 ms |
11160 KB |
Output is correct |
38 |
Correct |
359 ms |
11160 KB |
Output is correct |
39 |
Correct |
353 ms |
11160 KB |
Output is correct |
40 |
Correct |
353 ms |
11160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
743 ms |
20084 KB |
Output is correct |
12 |
Correct |
859 ms |
19660 KB |
Output is correct |
13 |
Correct |
701 ms |
18936 KB |
Output is correct |
14 |
Correct |
728 ms |
19064 KB |
Output is correct |
15 |
Correct |
793 ms |
20040 KB |
Output is correct |
16 |
Correct |
671 ms |
19352 KB |
Output is correct |
17 |
Correct |
670 ms |
19276 KB |
Output is correct |
18 |
Correct |
493 ms |
20984 KB |
Output is correct |
19 |
Correct |
562 ms |
18040 KB |
Output is correct |
20 |
Correct |
811 ms |
19700 KB |
Output is correct |
21 |
Correct |
808 ms |
20088 KB |
Output is correct |
22 |
Correct |
822 ms |
20344 KB |
Output is correct |
23 |
Correct |
712 ms |
19448 KB |
Output is correct |
24 |
Correct |
719 ms |
19064 KB |
Output is correct |
25 |
Correct |
887 ms |
21120 KB |
Output is correct |
26 |
Correct |
673 ms |
19536 KB |
Output is correct |
27 |
Correct |
670 ms |
19576 KB |
Output is correct |
28 |
Correct |
522 ms |
22024 KB |
Output is correct |
29 |
Correct |
570 ms |
18068 KB |
Output is correct |
30 |
Correct |
814 ms |
20348 KB |
Output is correct |
31 |
Correct |
669 ms |
20088 KB |
Output is correct |
32 |
Correct |
677 ms |
20128 KB |
Output is correct |
33 |
Correct |
616 ms |
19088 KB |
Output is correct |
34 |
Correct |
750 ms |
19172 KB |
Output is correct |
35 |
Correct |
671 ms |
19576 KB |
Output is correct |
36 |
Correct |
474 ms |
18200 KB |
Output is correct |
37 |
Correct |
731 ms |
20216 KB |
Output is correct |
38 |
Correct |
583 ms |
18108 KB |
Output is correct |
39 |
Correct |
698 ms |
19448 KB |
Output is correct |
40 |
Correct |
735 ms |
19068 KB |
Output is correct |
41 |
Correct |
356 ms |
11144 KB |
Output is correct |
42 |
Correct |
358 ms |
11160 KB |
Output is correct |
43 |
Correct |
349 ms |
11156 KB |
Output is correct |
44 |
Correct |
357 ms |
11160 KB |
Output is correct |
45 |
Correct |
372 ms |
11288 KB |
Output is correct |
46 |
Correct |
348 ms |
11160 KB |
Output is correct |
47 |
Correct |
347 ms |
11164 KB |
Output is correct |
48 |
Correct |
332 ms |
11416 KB |
Output is correct |
49 |
Correct |
346 ms |
11008 KB |
Output is correct |
50 |
Correct |
350 ms |
11160 KB |
Output is correct |
51 |
Correct |
361 ms |
11144 KB |
Output is correct |
52 |
Correct |
345 ms |
11156 KB |
Output is correct |
53 |
Correct |
340 ms |
11292 KB |
Output is correct |
54 |
Correct |
344 ms |
11156 KB |
Output is correct |
55 |
Correct |
349 ms |
11160 KB |
Output is correct |
56 |
Correct |
328 ms |
11032 KB |
Output is correct |
57 |
Correct |
360 ms |
11208 KB |
Output is correct |
58 |
Correct |
340 ms |
11028 KB |
Output is correct |
59 |
Correct |
356 ms |
11160 KB |
Output is correct |
60 |
Correct |
343 ms |
11160 KB |
Output is correct |
61 |
Correct |
342 ms |
11160 KB |
Output is correct |
62 |
Correct |
356 ms |
11160 KB |
Output is correct |
63 |
Correct |
358 ms |
11164 KB |
Output is correct |
64 |
Correct |
336 ms |
11036 KB |
Output is correct |
65 |
Correct |
358 ms |
11164 KB |
Output is correct |
66 |
Correct |
355 ms |
11160 KB |
Output is correct |
67 |
Correct |
359 ms |
11160 KB |
Output is correct |
68 |
Correct |
359 ms |
11160 KB |
Output is correct |
69 |
Correct |
353 ms |
11160 KB |
Output is correct |
70 |
Correct |
353 ms |
11160 KB |
Output is correct |
71 |
Correct |
1147 ms |
31016 KB |
Output is correct |
72 |
Correct |
1198 ms |
30944 KB |
Output is correct |
73 |
Correct |
1181 ms |
29464 KB |
Output is correct |
74 |
Correct |
1282 ms |
29852 KB |
Output is correct |
75 |
Correct |
1599 ms |
31896 KB |
Output is correct |
76 |
Correct |
1319 ms |
32672 KB |
Output is correct |
77 |
Correct |
1341 ms |
32408 KB |
Output is correct |
78 |
Correct |
849 ms |
36248 KB |
Output is correct |
79 |
Correct |
930 ms |
30232 KB |
Output is correct |
80 |
Correct |
1203 ms |
33360 KB |
Output is correct |
81 |
Correct |
1480 ms |
33304 KB |
Output is correct |
82 |
Correct |
1283 ms |
32280 KB |
Output is correct |
83 |
Correct |
971 ms |
31384 KB |
Output is correct |
84 |
Correct |
1261 ms |
32200 KB |
Output is correct |
85 |
Correct |
1378 ms |
32392 KB |
Output is correct |
86 |
Correct |
803 ms |
30228 KB |
Output is correct |
87 |
Correct |
1167 ms |
33304 KB |
Output is correct |
88 |
Correct |
932 ms |
30260 KB |
Output is correct |
89 |
Correct |
1155 ms |
31876 KB |
Output is correct |
90 |
Correct |
1267 ms |
32276 KB |
Output is correct |
91 |
Correct |
997 ms |
31384 KB |
Output is correct |
92 |
Correct |
1325 ms |
32424 KB |
Output is correct |
93 |
Correct |
1355 ms |
32344 KB |
Output is correct |
94 |
Correct |
794 ms |
30108 KB |
Output is correct |
95 |
Correct |
1335 ms |
32276 KB |
Output is correct |
96 |
Correct |
1344 ms |
32188 KB |
Output is correct |
97 |
Correct |
1336 ms |
32192 KB |
Output is correct |
98 |
Correct |
1378 ms |
32204 KB |
Output is correct |
99 |
Correct |
1379 ms |
32152 KB |
Output is correct |
100 |
Correct |
1343 ms |
32152 KB |
Output is correct |