#include <bits/stdc++.h>
using namespace std;
int nd,n,d,d2,p3[12],dh[177147],pst[177147],a[1ll<<20],dp[1ll<<9][177147];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t,rr,i,k,w,ww,mk,mkk,z;
string s;
cin>>nd>>t;
n=1ll<<nd;
d=min(nd,9);
d2=max(nd-9,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(i=0;i<1ll<<d;i++)
{
for(mk=0;mk<p3[d2];mk++)
{
if(dh[mk]==-1)
{
dp[i][mk]=a[i<<d2|pst[mk]];
}
else
{
dp[i][mk]=dp[i][mk-p3[dh[mk]]*2]+dp[i][mk-p3[dh[mk]]];
}
}
}
for(rr=0;rr<t;rr++)
{
cin>>s;
w=0;
ww=0;
for(i=0;i<d;i++)
{
k=(s[i]=='1')+2*(s[i]=='?');
w=w<<1|k%2;
ww=ww<<1|k/2;
}
mk=0;
for(i=0;i<d2;i++)
{
k=(s[d+i]=='1')+2*(s[d+i]=='?');
mk=mk*3+k;
}
z=0;
for(mkk=ww;1;mkk=mkk-1&ww)
{
z+=dp[mkk|w][mk];
if(!mkk)
{
break;
}
}
cout<<z<<"\n";
}
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:79:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
79 | for(mkk=ww;1;mkk=mkk-1&ww)
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3072 KB |
Output is correct |
2 |
Correct |
2 ms |
3072 KB |
Output is correct |
3 |
Correct |
2 ms |
3072 KB |
Output is correct |
4 |
Correct |
2 ms |
2944 KB |
Output is correct |
5 |
Correct |
2 ms |
3072 KB |
Output is correct |
6 |
Correct |
2 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3072 KB |
Output is correct |
2 |
Correct |
2 ms |
3072 KB |
Output is correct |
3 |
Correct |
2 ms |
3072 KB |
Output is correct |
4 |
Correct |
2 ms |
2944 KB |
Output is correct |
5 |
Correct |
2 ms |
3072 KB |
Output is correct |
6 |
Correct |
2 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
11 |
Correct |
243 ms |
7160 KB |
Output is correct |
12 |
Correct |
265 ms |
6828 KB |
Output is correct |
13 |
Correct |
198 ms |
6136 KB |
Output is correct |
14 |
Correct |
203 ms |
6264 KB |
Output is correct |
15 |
Correct |
271 ms |
7160 KB |
Output is correct |
16 |
Correct |
211 ms |
6384 KB |
Output is correct |
17 |
Correct |
226 ms |
6332 KB |
Output is correct |
18 |
Correct |
1060 ms |
8416 KB |
Output is correct |
19 |
Correct |
194 ms |
15864 KB |
Output is correct |
20 |
Correct |
265 ms |
17568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3072 KB |
Output is correct |
2 |
Correct |
2 ms |
3072 KB |
Output is correct |
3 |
Correct |
2 ms |
3072 KB |
Output is correct |
4 |
Correct |
2 ms |
2944 KB |
Output is correct |
5 |
Correct |
2 ms |
3072 KB |
Output is correct |
6 |
Correct |
2 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
11 |
Correct |
243 ms |
7160 KB |
Output is correct |
12 |
Correct |
265 ms |
6828 KB |
Output is correct |
13 |
Correct |
198 ms |
6136 KB |
Output is correct |
14 |
Correct |
203 ms |
6264 KB |
Output is correct |
15 |
Correct |
271 ms |
7160 KB |
Output is correct |
16 |
Correct |
211 ms |
6384 KB |
Output is correct |
17 |
Correct |
226 ms |
6332 KB |
Output is correct |
18 |
Correct |
1060 ms |
8416 KB |
Output is correct |
19 |
Correct |
194 ms |
15864 KB |
Output is correct |
20 |
Correct |
265 ms |
17568 KB |
Output is correct |
21 |
Correct |
265 ms |
20928 KB |
Output is correct |
22 |
Correct |
291 ms |
21112 KB |
Output is correct |
23 |
Correct |
225 ms |
20088 KB |
Output is correct |
24 |
Correct |
223 ms |
20088 KB |
Output is correct |
25 |
Correct |
315 ms |
22008 KB |
Output is correct |
26 |
Correct |
231 ms |
20472 KB |
Output is correct |
27 |
Correct |
237 ms |
20600 KB |
Output is correct |
28 |
Correct |
1076 ms |
23160 KB |
Output is correct |
29 |
Correct |
207 ms |
19064 KB |
Output is correct |
30 |
Correct |
280 ms |
21112 KB |
Output is correct |
31 |
Correct |
244 ms |
20984 KB |
Output is correct |
32 |
Correct |
227 ms |
20984 KB |
Output is correct |
33 |
Correct |
215 ms |
19836 KB |
Output is correct |
34 |
Correct |
224 ms |
19960 KB |
Output is correct |
35 |
Correct |
233 ms |
20472 KB |
Output is correct |
36 |
Correct |
199 ms |
19096 KB |
Output is correct |
37 |
Correct |
239 ms |
20984 KB |
Output is correct |
38 |
Correct |
204 ms |
18940 KB |
Output is correct |
39 |
Correct |
229 ms |
20196 KB |
Output is correct |
40 |
Correct |
225 ms |
19960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3072 KB |
Output is correct |
2 |
Correct |
2 ms |
3072 KB |
Output is correct |
3 |
Correct |
2 ms |
3072 KB |
Output is correct |
4 |
Correct |
2 ms |
2944 KB |
Output is correct |
5 |
Correct |
2 ms |
3072 KB |
Output is correct |
6 |
Correct |
2 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
11 |
Runtime error |
83 ms |
65540 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3072 KB |
Output is correct |
2 |
Correct |
2 ms |
3072 KB |
Output is correct |
3 |
Correct |
2 ms |
3072 KB |
Output is correct |
4 |
Correct |
2 ms |
2944 KB |
Output is correct |
5 |
Correct |
2 ms |
3072 KB |
Output is correct |
6 |
Correct |
2 ms |
2944 KB |
Output is correct |
7 |
Correct |
2 ms |
3072 KB |
Output is correct |
8 |
Correct |
3 ms |
3072 KB |
Output is correct |
9 |
Correct |
2 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
11 |
Correct |
243 ms |
7160 KB |
Output is correct |
12 |
Correct |
265 ms |
6828 KB |
Output is correct |
13 |
Correct |
198 ms |
6136 KB |
Output is correct |
14 |
Correct |
203 ms |
6264 KB |
Output is correct |
15 |
Correct |
271 ms |
7160 KB |
Output is correct |
16 |
Correct |
211 ms |
6384 KB |
Output is correct |
17 |
Correct |
226 ms |
6332 KB |
Output is correct |
18 |
Correct |
1060 ms |
8416 KB |
Output is correct |
19 |
Correct |
194 ms |
15864 KB |
Output is correct |
20 |
Correct |
265 ms |
17568 KB |
Output is correct |
21 |
Correct |
265 ms |
20928 KB |
Output is correct |
22 |
Correct |
291 ms |
21112 KB |
Output is correct |
23 |
Correct |
225 ms |
20088 KB |
Output is correct |
24 |
Correct |
223 ms |
20088 KB |
Output is correct |
25 |
Correct |
315 ms |
22008 KB |
Output is correct |
26 |
Correct |
231 ms |
20472 KB |
Output is correct |
27 |
Correct |
237 ms |
20600 KB |
Output is correct |
28 |
Correct |
1076 ms |
23160 KB |
Output is correct |
29 |
Correct |
207 ms |
19064 KB |
Output is correct |
30 |
Correct |
280 ms |
21112 KB |
Output is correct |
31 |
Correct |
244 ms |
20984 KB |
Output is correct |
32 |
Correct |
227 ms |
20984 KB |
Output is correct |
33 |
Correct |
215 ms |
19836 KB |
Output is correct |
34 |
Correct |
224 ms |
19960 KB |
Output is correct |
35 |
Correct |
233 ms |
20472 KB |
Output is correct |
36 |
Correct |
199 ms |
19096 KB |
Output is correct |
37 |
Correct |
239 ms |
20984 KB |
Output is correct |
38 |
Correct |
204 ms |
18940 KB |
Output is correct |
39 |
Correct |
229 ms |
20196 KB |
Output is correct |
40 |
Correct |
225 ms |
19960 KB |
Output is correct |
41 |
Runtime error |
83 ms |
65540 KB |
Execution killed with signal 9 |
42 |
Halted |
0 ms |
0 KB |
- |