#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int n,q,C[1148576],M[20],dp[1794323],vs;
pair < int , int > v[1794323];
main () {
ios::sync_with_stdio(false);
cin>>n>>q;
M[0]=1;
for (int i=1; i<=n; i++)
M[i]=M[i-1]*3;
for (int i=0; i<(1<<n); i++) {
char c;
cin>>c;
C[i]=c-'0';
int x=0;
for (int j=0; j<n; j++)
if (i&(1<<j)) x+=M[j];
dp[x]+=C[i];
}
for (int i=0; i<M[n]; i++) {
int x=i;
for (int j=n-1; j>=0; j--) {
if (x-2*M[j]>=0) {
x-=2*M[j];
dp[i]=(dp[i-2*M[j]]+dp[i-M[j]]);
}
else
if (x-M[j]>=0) x-=M[j];
}
}
for (int i=1; i<=q; i++) {
string s;
int x=0;
cin>>s;
for (int j=0; j<s.size(); j++)
if (s[s.size()-j-1]=='?') x+=2*M[j];
else
if (s[s.size()-j-1]=='1') x+=M[j];
printf("%d\n",dp[x]);
}
}
Compilation message
snake_escaping.cpp:8:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:44:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0; j<s.size(); j++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
252 ms |
7288 KB |
Output is correct |
12 |
Correct |
272 ms |
14968 KB |
Output is correct |
13 |
Correct |
280 ms |
14328 KB |
Output is correct |
14 |
Correct |
284 ms |
14320 KB |
Output is correct |
15 |
Correct |
280 ms |
15352 KB |
Output is correct |
16 |
Correct |
298 ms |
14584 KB |
Output is correct |
17 |
Correct |
301 ms |
14524 KB |
Output is correct |
18 |
Correct |
206 ms |
16508 KB |
Output is correct |
19 |
Correct |
253 ms |
13304 KB |
Output is correct |
20 |
Correct |
271 ms |
15096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
252 ms |
7288 KB |
Output is correct |
12 |
Correct |
272 ms |
14968 KB |
Output is correct |
13 |
Correct |
280 ms |
14328 KB |
Output is correct |
14 |
Correct |
284 ms |
14320 KB |
Output is correct |
15 |
Correct |
280 ms |
15352 KB |
Output is correct |
16 |
Correct |
298 ms |
14584 KB |
Output is correct |
17 |
Correct |
301 ms |
14524 KB |
Output is correct |
18 |
Correct |
206 ms |
16508 KB |
Output is correct |
19 |
Correct |
253 ms |
13304 KB |
Output is correct |
20 |
Correct |
271 ms |
15096 KB |
Output is correct |
21 |
Correct |
342 ms |
24312 KB |
Output is correct |
22 |
Correct |
361 ms |
24440 KB |
Output is correct |
23 |
Correct |
416 ms |
23568 KB |
Output is correct |
24 |
Correct |
387 ms |
23412 KB |
Output is correct |
25 |
Correct |
361 ms |
25464 KB |
Output is correct |
26 |
Correct |
421 ms |
23916 KB |
Output is correct |
27 |
Correct |
450 ms |
23980 KB |
Output is correct |
28 |
Correct |
268 ms |
26360 KB |
Output is correct |
29 |
Correct |
337 ms |
22264 KB |
Output is correct |
30 |
Correct |
352 ms |
24568 KB |
Output is correct |
31 |
Correct |
463 ms |
24344 KB |
Output is correct |
32 |
Correct |
428 ms |
24324 KB |
Output is correct |
33 |
Correct |
367 ms |
23288 KB |
Output is correct |
34 |
Correct |
467 ms |
23288 KB |
Output is correct |
35 |
Correct |
432 ms |
23776 KB |
Output is correct |
36 |
Correct |
260 ms |
22260 KB |
Output is correct |
37 |
Correct |
339 ms |
24376 KB |
Output is correct |
38 |
Correct |
347 ms |
22432 KB |
Output is correct |
39 |
Correct |
384 ms |
23416 KB |
Output is correct |
40 |
Correct |
406 ms |
23264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Runtime error |
8 ms |
2680 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
3 |
Correct |
4 ms |
632 KB |
Output is correct |
4 |
Correct |
4 ms |
632 KB |
Output is correct |
5 |
Correct |
4 ms |
632 KB |
Output is correct |
6 |
Correct |
4 ms |
632 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
632 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
252 ms |
7288 KB |
Output is correct |
12 |
Correct |
272 ms |
14968 KB |
Output is correct |
13 |
Correct |
280 ms |
14328 KB |
Output is correct |
14 |
Correct |
284 ms |
14320 KB |
Output is correct |
15 |
Correct |
280 ms |
15352 KB |
Output is correct |
16 |
Correct |
298 ms |
14584 KB |
Output is correct |
17 |
Correct |
301 ms |
14524 KB |
Output is correct |
18 |
Correct |
206 ms |
16508 KB |
Output is correct |
19 |
Correct |
253 ms |
13304 KB |
Output is correct |
20 |
Correct |
271 ms |
15096 KB |
Output is correct |
21 |
Correct |
342 ms |
24312 KB |
Output is correct |
22 |
Correct |
361 ms |
24440 KB |
Output is correct |
23 |
Correct |
416 ms |
23568 KB |
Output is correct |
24 |
Correct |
387 ms |
23412 KB |
Output is correct |
25 |
Correct |
361 ms |
25464 KB |
Output is correct |
26 |
Correct |
421 ms |
23916 KB |
Output is correct |
27 |
Correct |
450 ms |
23980 KB |
Output is correct |
28 |
Correct |
268 ms |
26360 KB |
Output is correct |
29 |
Correct |
337 ms |
22264 KB |
Output is correct |
30 |
Correct |
352 ms |
24568 KB |
Output is correct |
31 |
Correct |
463 ms |
24344 KB |
Output is correct |
32 |
Correct |
428 ms |
24324 KB |
Output is correct |
33 |
Correct |
367 ms |
23288 KB |
Output is correct |
34 |
Correct |
467 ms |
23288 KB |
Output is correct |
35 |
Correct |
432 ms |
23776 KB |
Output is correct |
36 |
Correct |
260 ms |
22260 KB |
Output is correct |
37 |
Correct |
339 ms |
24376 KB |
Output is correct |
38 |
Correct |
347 ms |
22432 KB |
Output is correct |
39 |
Correct |
384 ms |
23416 KB |
Output is correct |
40 |
Correct |
406 ms |
23264 KB |
Output is correct |
41 |
Runtime error |
8 ms |
2680 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
42 |
Halted |
0 ms |
0 KB |
- |