#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()
{
int M,i,j,ok,a,b,c;
scanf("%d %d",&N,&M);
scanf("%s",all);
for(i=0;i<(1<<N);i++) con1[0][i]=all[i]-'0';
for(i=0;i<(1<<N);i++) con2[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];
if(j&(1<<i)) con1[1-i%2][j]+=con1[i%2][j-(1<<i)];
}
}
for(i=0;i<N;i++)
{
for(j=0;j<(1<<N);j++)
{
con2[1-i%2][j]=con2[i%2][j];
if((j&(1<<i))==0) 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:67:15: warning: unused variable 'ok' [-Wunused-variable]
67 | int M,i,j,ok,a,b,c;
| ^~
snake_escaping.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | scanf("%d %d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
69 | scanf("%s",all);
| ~~~~~^~~~~~~~~~
snake_escaping.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
92 | scanf("%s",tt);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 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 |
2 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 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 |
2 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 |
322 ms |
4584 KB |
Output is correct |
12 |
Correct |
380 ms |
4260 KB |
Output is correct |
13 |
Correct |
387 ms |
3564 KB |
Output is correct |
14 |
Correct |
537 ms |
3436 KB |
Output is correct |
15 |
Correct |
421 ms |
4588 KB |
Output is correct |
16 |
Correct |
510 ms |
3764 KB |
Output is correct |
17 |
Correct |
475 ms |
3692 KB |
Output is correct |
18 |
Correct |
254 ms |
5484 KB |
Output is correct |
19 |
Correct |
286 ms |
2668 KB |
Output is correct |
20 |
Correct |
343 ms |
4332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 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 |
2 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 |
322 ms |
4584 KB |
Output is correct |
12 |
Correct |
380 ms |
4260 KB |
Output is correct |
13 |
Correct |
387 ms |
3564 KB |
Output is correct |
14 |
Correct |
537 ms |
3436 KB |
Output is correct |
15 |
Correct |
421 ms |
4588 KB |
Output is correct |
16 |
Correct |
510 ms |
3764 KB |
Output is correct |
17 |
Correct |
475 ms |
3692 KB |
Output is correct |
18 |
Correct |
254 ms |
5484 KB |
Output is correct |
19 |
Correct |
286 ms |
2668 KB |
Output is correct |
20 |
Correct |
343 ms |
4332 KB |
Output is correct |
21 |
Correct |
453 ms |
4588 KB |
Output is correct |
22 |
Correct |
452 ms |
4844 KB |
Output is correct |
23 |
Correct |
557 ms |
4076 KB |
Output is correct |
24 |
Correct |
843 ms |
3804 KB |
Output is correct |
25 |
Correct |
489 ms |
5740 KB |
Output is correct |
26 |
Correct |
686 ms |
4240 KB |
Output is correct |
27 |
Correct |
649 ms |
4144 KB |
Output is correct |
28 |
Correct |
275 ms |
6636 KB |
Output is correct |
29 |
Correct |
363 ms |
2796 KB |
Output is correct |
30 |
Correct |
426 ms |
4844 KB |
Output is correct |
31 |
Correct |
640 ms |
4724 KB |
Output is correct |
32 |
Correct |
848 ms |
4700 KB |
Output is correct |
33 |
Correct |
447 ms |
3564 KB |
Output is correct |
34 |
Correct |
699 ms |
3692 KB |
Output is correct |
35 |
Correct |
618 ms |
4148 KB |
Output is correct |
36 |
Correct |
293 ms |
2668 KB |
Output is correct |
37 |
Correct |
382 ms |
4716 KB |
Output is correct |
38 |
Correct |
329 ms |
2704 KB |
Output is correct |
39 |
Correct |
545 ms |
3820 KB |
Output is correct |
40 |
Correct |
677 ms |
3720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 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 |
2 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 |
96 ms |
18284 KB |
Output is correct |
12 |
Correct |
99 ms |
18144 KB |
Output is correct |
13 |
Correct |
129 ms |
18152 KB |
Output is correct |
14 |
Correct |
202 ms |
18284 KB |
Output is correct |
15 |
Correct |
111 ms |
18184 KB |
Output is correct |
16 |
Correct |
202 ms |
18156 KB |
Output is correct |
17 |
Correct |
171 ms |
18156 KB |
Output is correct |
18 |
Correct |
89 ms |
18412 KB |
Output is correct |
19 |
Correct |
91 ms |
18028 KB |
Output is correct |
20 |
Correct |
96 ms |
18156 KB |
Output is correct |
21 |
Correct |
143 ms |
18284 KB |
Output is correct |
22 |
Correct |
210 ms |
18028 KB |
Output is correct |
23 |
Correct |
112 ms |
18156 KB |
Output is correct |
24 |
Correct |
207 ms |
18156 KB |
Output is correct |
25 |
Correct |
171 ms |
18156 KB |
Output is correct |
26 |
Correct |
105 ms |
18028 KB |
Output is correct |
27 |
Correct |
99 ms |
18156 KB |
Output is correct |
28 |
Correct |
94 ms |
18028 KB |
Output is correct |
29 |
Correct |
128 ms |
18028 KB |
Output is correct |
30 |
Correct |
151 ms |
18028 KB |
Output is correct |
31 |
Correct |
102 ms |
18028 KB |
Output is correct |
32 |
Correct |
225 ms |
18156 KB |
Output is correct |
33 |
Correct |
172 ms |
18216 KB |
Output is correct |
34 |
Correct |
84 ms |
17944 KB |
Output is correct |
35 |
Correct |
142 ms |
18156 KB |
Output is correct |
36 |
Correct |
145 ms |
18156 KB |
Output is correct |
37 |
Correct |
150 ms |
18140 KB |
Output is correct |
38 |
Correct |
142 ms |
18028 KB |
Output is correct |
39 |
Correct |
144 ms |
18028 KB |
Output is correct |
40 |
Correct |
149 ms |
18028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 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 |
2 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 |
322 ms |
4584 KB |
Output is correct |
12 |
Correct |
380 ms |
4260 KB |
Output is correct |
13 |
Correct |
387 ms |
3564 KB |
Output is correct |
14 |
Correct |
537 ms |
3436 KB |
Output is correct |
15 |
Correct |
421 ms |
4588 KB |
Output is correct |
16 |
Correct |
510 ms |
3764 KB |
Output is correct |
17 |
Correct |
475 ms |
3692 KB |
Output is correct |
18 |
Correct |
254 ms |
5484 KB |
Output is correct |
19 |
Correct |
286 ms |
2668 KB |
Output is correct |
20 |
Correct |
343 ms |
4332 KB |
Output is correct |
21 |
Correct |
453 ms |
4588 KB |
Output is correct |
22 |
Correct |
452 ms |
4844 KB |
Output is correct |
23 |
Correct |
557 ms |
4076 KB |
Output is correct |
24 |
Correct |
843 ms |
3804 KB |
Output is correct |
25 |
Correct |
489 ms |
5740 KB |
Output is correct |
26 |
Correct |
686 ms |
4240 KB |
Output is correct |
27 |
Correct |
649 ms |
4144 KB |
Output is correct |
28 |
Correct |
275 ms |
6636 KB |
Output is correct |
29 |
Correct |
363 ms |
2796 KB |
Output is correct |
30 |
Correct |
426 ms |
4844 KB |
Output is correct |
31 |
Correct |
640 ms |
4724 KB |
Output is correct |
32 |
Correct |
848 ms |
4700 KB |
Output is correct |
33 |
Correct |
447 ms |
3564 KB |
Output is correct |
34 |
Correct |
699 ms |
3692 KB |
Output is correct |
35 |
Correct |
618 ms |
4148 KB |
Output is correct |
36 |
Correct |
293 ms |
2668 KB |
Output is correct |
37 |
Correct |
382 ms |
4716 KB |
Output is correct |
38 |
Correct |
329 ms |
2704 KB |
Output is correct |
39 |
Correct |
545 ms |
3820 KB |
Output is correct |
40 |
Correct |
677 ms |
3720 KB |
Output is correct |
41 |
Correct |
96 ms |
18284 KB |
Output is correct |
42 |
Correct |
99 ms |
18144 KB |
Output is correct |
43 |
Correct |
129 ms |
18152 KB |
Output is correct |
44 |
Correct |
202 ms |
18284 KB |
Output is correct |
45 |
Correct |
111 ms |
18184 KB |
Output is correct |
46 |
Correct |
202 ms |
18156 KB |
Output is correct |
47 |
Correct |
171 ms |
18156 KB |
Output is correct |
48 |
Correct |
89 ms |
18412 KB |
Output is correct |
49 |
Correct |
91 ms |
18028 KB |
Output is correct |
50 |
Correct |
96 ms |
18156 KB |
Output is correct |
51 |
Correct |
143 ms |
18284 KB |
Output is correct |
52 |
Correct |
210 ms |
18028 KB |
Output is correct |
53 |
Correct |
112 ms |
18156 KB |
Output is correct |
54 |
Correct |
207 ms |
18156 KB |
Output is correct |
55 |
Correct |
171 ms |
18156 KB |
Output is correct |
56 |
Correct |
105 ms |
18028 KB |
Output is correct |
57 |
Correct |
99 ms |
18156 KB |
Output is correct |
58 |
Correct |
94 ms |
18028 KB |
Output is correct |
59 |
Correct |
128 ms |
18028 KB |
Output is correct |
60 |
Correct |
151 ms |
18028 KB |
Output is correct |
61 |
Correct |
102 ms |
18028 KB |
Output is correct |
62 |
Correct |
225 ms |
18156 KB |
Output is correct |
63 |
Correct |
172 ms |
18216 KB |
Output is correct |
64 |
Correct |
84 ms |
17944 KB |
Output is correct |
65 |
Correct |
142 ms |
18156 KB |
Output is correct |
66 |
Correct |
145 ms |
18156 KB |
Output is correct |
67 |
Correct |
150 ms |
18140 KB |
Output is correct |
68 |
Correct |
142 ms |
18028 KB |
Output is correct |
69 |
Correct |
144 ms |
18028 KB |
Output is correct |
70 |
Correct |
149 ms |
18028 KB |
Output is correct |
71 |
Correct |
673 ms |
23260 KB |
Output is correct |
72 |
Correct |
721 ms |
23244 KB |
Output is correct |
73 |
Correct |
1464 ms |
21812 KB |
Output is correct |
74 |
Execution timed out |
2017 ms |
20964 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |