#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string.h>
#include <map>
#include <utility>
#include <algorithm>
#include <stack>
using namespace std;
char all[1148576];
char tt[25];
int con1[2][1100005];
int con2[2][1100005];
int ans=0;
int N;
void F(int x,int y,int z)
{
if(x==N)
{
if(z%2==0) ans+=con1[N%2][y];
else ans-=con1[N%2][y];
return;
}
if(tt[x]=='1')
{
F(x+1,y+(1<<(N-x-1)),z);
F(x+1,y,z+1);
}
else if(tt[x]=='0') F(x+1,y,z);
else F(x+1,y+(1<<(N-x-1)),z);
}
void F2(int x,int y)
{
if(x==N)
{
ans+=(all[y]-'0');
return;
}
if(tt[x]=='?')
{
F2(x+1,y);
F2(x+1,y+(1<<(N-x-1)));
}
else F2(x+1,y+(1<<(N-x-1))*(tt[x]-'0'));
}
void F3(int x,int y,int z)
{
if(x==N)
{
if(z%2==0) ans+=con2[N%2][y];
else ans-=con2[N%2][y];
return;
}
if(tt[x]=='0')
{
F3(x+1,y+(1<<(N-x-1)),z+1);
F3(x+1,y,z);
}
else if(tt[x]=='1') F3(x+1,y+(1<<(N-x-1)),z);
else F3(x+1,y,z);
}
int main()
{
//freopen("05-05.txt","rt",stdin);
//freopen("tt.txt","w+t",stdout);
int M,i,j,ok,a,b,c;
scanf("%d %d",&N,&M);
scanf("%s",all);
for(i=0;i<(1<<N);i++) con2[0][i]=con1[0][i]=all[i]-'0';
for(i=0;i<N;i++)
{
for(j=0;j<(1<<N);j++)
{
con1[1-i%2][j]=con1[i%2][j];
con2[1-i%2][j]=con2[i%2][j];
if(j&(1<<i)) con1[1-i%2][j]+=con1[i%2][j-(1<<i)];
else con2[1-i%2][j]+=con2[i%2][j+(1<<i)];
}
}
while(M--)
{
scanf("%s",tt);
ans=0;
a=0;
b=0;
c=0;
for(i=0;i<N;i++)
{
if(tt[i]=='?') a++;
else if(tt[i]=='1') b++;
else c++;
}
if(b<=a&&b<=c) F(0,0,0);
else if(a<=b&&a<=c) F2(0,0);
else if(c<=b&&c<=a) F3(0,0,0);
printf("%d\n",ans);
}
return 0;
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:69:15: warning: unused variable 'ok' [-Wunused-variable]
69 | int M,i,j,ok,a,b,c;
| ^~
snake_escaping.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
70 | scanf("%d %d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
71 | scanf("%s",all);
| ~~~~~^~~~~~~~~~
snake_escaping.cpp:88:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
88 | scanf("%s",tt);
| ~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
317 ms |
4368 KB |
Output is correct |
12 |
Correct |
389 ms |
4204 KB |
Output is correct |
13 |
Correct |
393 ms |
3248 KB |
Output is correct |
14 |
Correct |
568 ms |
3564 KB |
Output is correct |
15 |
Correct |
427 ms |
4352 KB |
Output is correct |
16 |
Correct |
477 ms |
3528 KB |
Output is correct |
17 |
Correct |
486 ms |
3564 KB |
Output is correct |
18 |
Correct |
252 ms |
5484 KB |
Output is correct |
19 |
Correct |
294 ms |
2412 KB |
Output is correct |
20 |
Correct |
350 ms |
4304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
317 ms |
4368 KB |
Output is correct |
12 |
Correct |
389 ms |
4204 KB |
Output is correct |
13 |
Correct |
393 ms |
3248 KB |
Output is correct |
14 |
Correct |
568 ms |
3564 KB |
Output is correct |
15 |
Correct |
427 ms |
4352 KB |
Output is correct |
16 |
Correct |
477 ms |
3528 KB |
Output is correct |
17 |
Correct |
486 ms |
3564 KB |
Output is correct |
18 |
Correct |
252 ms |
5484 KB |
Output is correct |
19 |
Correct |
294 ms |
2412 KB |
Output is correct |
20 |
Correct |
350 ms |
4304 KB |
Output is correct |
21 |
Correct |
391 ms |
4568 KB |
Output is correct |
22 |
Correct |
417 ms |
4716 KB |
Output is correct |
23 |
Correct |
564 ms |
3692 KB |
Output is correct |
24 |
Correct |
887 ms |
3588 KB |
Output is correct |
25 |
Correct |
539 ms |
5484 KB |
Output is correct |
26 |
Correct |
682 ms |
4204 KB |
Output is correct |
27 |
Correct |
634 ms |
4076 KB |
Output is correct |
28 |
Correct |
280 ms |
6508 KB |
Output is correct |
29 |
Correct |
323 ms |
2820 KB |
Output is correct |
30 |
Correct |
422 ms |
4764 KB |
Output is correct |
31 |
Correct |
619 ms |
4536 KB |
Output is correct |
32 |
Correct |
908 ms |
4604 KB |
Output is correct |
33 |
Correct |
474 ms |
3460 KB |
Output is correct |
34 |
Correct |
784 ms |
3552 KB |
Output is correct |
35 |
Correct |
677 ms |
4244 KB |
Output is correct |
36 |
Correct |
335 ms |
2668 KB |
Output is correct |
37 |
Correct |
372 ms |
4776 KB |
Output is correct |
38 |
Correct |
344 ms |
2540 KB |
Output is correct |
39 |
Correct |
549 ms |
3692 KB |
Output is correct |
40 |
Correct |
645 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
91 ms |
18028 KB |
Output is correct |
12 |
Correct |
85 ms |
18028 KB |
Output is correct |
13 |
Correct |
126 ms |
18156 KB |
Output is correct |
14 |
Correct |
206 ms |
18028 KB |
Output is correct |
15 |
Correct |
97 ms |
18156 KB |
Output is correct |
16 |
Correct |
180 ms |
18028 KB |
Output is correct |
17 |
Correct |
155 ms |
18028 KB |
Output is correct |
18 |
Correct |
73 ms |
18156 KB |
Output is correct |
19 |
Correct |
77 ms |
17900 KB |
Output is correct |
20 |
Correct |
86 ms |
18028 KB |
Output is correct |
21 |
Correct |
143 ms |
18028 KB |
Output is correct |
22 |
Correct |
196 ms |
18028 KB |
Output is correct |
23 |
Correct |
89 ms |
17964 KB |
Output is correct |
24 |
Correct |
175 ms |
17952 KB |
Output is correct |
25 |
Correct |
156 ms |
18028 KB |
Output is correct |
26 |
Correct |
74 ms |
17900 KB |
Output is correct |
27 |
Correct |
83 ms |
18028 KB |
Output is correct |
28 |
Correct |
95 ms |
17900 KB |
Output is correct |
29 |
Correct |
112 ms |
17900 KB |
Output is correct |
30 |
Correct |
133 ms |
18028 KB |
Output is correct |
31 |
Correct |
89 ms |
18020 KB |
Output is correct |
32 |
Correct |
201 ms |
18028 KB |
Output is correct |
33 |
Correct |
151 ms |
18028 KB |
Output is correct |
34 |
Correct |
73 ms |
18028 KB |
Output is correct |
35 |
Correct |
126 ms |
18156 KB |
Output is correct |
36 |
Correct |
143 ms |
18028 KB |
Output is correct |
37 |
Correct |
134 ms |
18156 KB |
Output is correct |
38 |
Correct |
126 ms |
18028 KB |
Output is correct |
39 |
Correct |
131 ms |
18028 KB |
Output is correct |
40 |
Correct |
130 ms |
18076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
317 ms |
4368 KB |
Output is correct |
12 |
Correct |
389 ms |
4204 KB |
Output is correct |
13 |
Correct |
393 ms |
3248 KB |
Output is correct |
14 |
Correct |
568 ms |
3564 KB |
Output is correct |
15 |
Correct |
427 ms |
4352 KB |
Output is correct |
16 |
Correct |
477 ms |
3528 KB |
Output is correct |
17 |
Correct |
486 ms |
3564 KB |
Output is correct |
18 |
Correct |
252 ms |
5484 KB |
Output is correct |
19 |
Correct |
294 ms |
2412 KB |
Output is correct |
20 |
Correct |
350 ms |
4304 KB |
Output is correct |
21 |
Correct |
391 ms |
4568 KB |
Output is correct |
22 |
Correct |
417 ms |
4716 KB |
Output is correct |
23 |
Correct |
564 ms |
3692 KB |
Output is correct |
24 |
Correct |
887 ms |
3588 KB |
Output is correct |
25 |
Correct |
539 ms |
5484 KB |
Output is correct |
26 |
Correct |
682 ms |
4204 KB |
Output is correct |
27 |
Correct |
634 ms |
4076 KB |
Output is correct |
28 |
Correct |
280 ms |
6508 KB |
Output is correct |
29 |
Correct |
323 ms |
2820 KB |
Output is correct |
30 |
Correct |
422 ms |
4764 KB |
Output is correct |
31 |
Correct |
619 ms |
4536 KB |
Output is correct |
32 |
Correct |
908 ms |
4604 KB |
Output is correct |
33 |
Correct |
474 ms |
3460 KB |
Output is correct |
34 |
Correct |
784 ms |
3552 KB |
Output is correct |
35 |
Correct |
677 ms |
4244 KB |
Output is correct |
36 |
Correct |
335 ms |
2668 KB |
Output is correct |
37 |
Correct |
372 ms |
4776 KB |
Output is correct |
38 |
Correct |
344 ms |
2540 KB |
Output is correct |
39 |
Correct |
549 ms |
3692 KB |
Output is correct |
40 |
Correct |
645 ms |
3564 KB |
Output is correct |
41 |
Correct |
91 ms |
18028 KB |
Output is correct |
42 |
Correct |
85 ms |
18028 KB |
Output is correct |
43 |
Correct |
126 ms |
18156 KB |
Output is correct |
44 |
Correct |
206 ms |
18028 KB |
Output is correct |
45 |
Correct |
97 ms |
18156 KB |
Output is correct |
46 |
Correct |
180 ms |
18028 KB |
Output is correct |
47 |
Correct |
155 ms |
18028 KB |
Output is correct |
48 |
Correct |
73 ms |
18156 KB |
Output is correct |
49 |
Correct |
77 ms |
17900 KB |
Output is correct |
50 |
Correct |
86 ms |
18028 KB |
Output is correct |
51 |
Correct |
143 ms |
18028 KB |
Output is correct |
52 |
Correct |
196 ms |
18028 KB |
Output is correct |
53 |
Correct |
89 ms |
17964 KB |
Output is correct |
54 |
Correct |
175 ms |
17952 KB |
Output is correct |
55 |
Correct |
156 ms |
18028 KB |
Output is correct |
56 |
Correct |
74 ms |
17900 KB |
Output is correct |
57 |
Correct |
83 ms |
18028 KB |
Output is correct |
58 |
Correct |
95 ms |
17900 KB |
Output is correct |
59 |
Correct |
112 ms |
17900 KB |
Output is correct |
60 |
Correct |
133 ms |
18028 KB |
Output is correct |
61 |
Correct |
89 ms |
18020 KB |
Output is correct |
62 |
Correct |
201 ms |
18028 KB |
Output is correct |
63 |
Correct |
151 ms |
18028 KB |
Output is correct |
64 |
Correct |
73 ms |
18028 KB |
Output is correct |
65 |
Correct |
126 ms |
18156 KB |
Output is correct |
66 |
Correct |
143 ms |
18028 KB |
Output is correct |
67 |
Correct |
134 ms |
18156 KB |
Output is correct |
68 |
Correct |
126 ms |
18028 KB |
Output is correct |
69 |
Correct |
131 ms |
18028 KB |
Output is correct |
70 |
Correct |
130 ms |
18076 KB |
Output is correct |
71 |
Correct |
662 ms |
23132 KB |
Output is correct |
72 |
Correct |
667 ms |
22932 KB |
Output is correct |
73 |
Correct |
1410 ms |
21496 KB |
Output is correct |
74 |
Execution timed out |
2082 ms |
20636 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |