#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[5][1100005];
int con2[5][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 |
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 |
# |
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 |
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 |
315 ms |
4408 KB |
Output is correct |
12 |
Correct |
335 ms |
4144 KB |
Output is correct |
13 |
Correct |
382 ms |
3308 KB |
Output is correct |
14 |
Correct |
549 ms |
3436 KB |
Output is correct |
15 |
Correct |
405 ms |
4392 KB |
Output is correct |
16 |
Correct |
492 ms |
3564 KB |
Output is correct |
17 |
Correct |
464 ms |
3692 KB |
Output is correct |
18 |
Correct |
256 ms |
5348 KB |
Output is correct |
19 |
Correct |
283 ms |
2412 KB |
Output is correct |
20 |
Correct |
347 ms |
4076 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 |
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 |
315 ms |
4408 KB |
Output is correct |
12 |
Correct |
335 ms |
4144 KB |
Output is correct |
13 |
Correct |
382 ms |
3308 KB |
Output is correct |
14 |
Correct |
549 ms |
3436 KB |
Output is correct |
15 |
Correct |
405 ms |
4392 KB |
Output is correct |
16 |
Correct |
492 ms |
3564 KB |
Output is correct |
17 |
Correct |
464 ms |
3692 KB |
Output is correct |
18 |
Correct |
256 ms |
5348 KB |
Output is correct |
19 |
Correct |
283 ms |
2412 KB |
Output is correct |
20 |
Correct |
347 ms |
4076 KB |
Output is correct |
21 |
Correct |
376 ms |
4616 KB |
Output is correct |
22 |
Correct |
397 ms |
4716 KB |
Output is correct |
23 |
Correct |
535 ms |
3692 KB |
Output is correct |
24 |
Correct |
814 ms |
3564 KB |
Output is correct |
25 |
Correct |
489 ms |
5484 KB |
Output is correct |
26 |
Correct |
664 ms |
4076 KB |
Output is correct |
27 |
Correct |
623 ms |
3948 KB |
Output is correct |
28 |
Correct |
278 ms |
6636 KB |
Output is correct |
29 |
Correct |
314 ms |
2564 KB |
Output is correct |
30 |
Correct |
415 ms |
4716 KB |
Output is correct |
31 |
Correct |
616 ms |
4588 KB |
Output is correct |
32 |
Correct |
836 ms |
4524 KB |
Output is correct |
33 |
Correct |
440 ms |
3436 KB |
Output is correct |
34 |
Correct |
714 ms |
3724 KB |
Output is correct |
35 |
Correct |
629 ms |
4076 KB |
Output is correct |
36 |
Correct |
279 ms |
2540 KB |
Output is correct |
37 |
Correct |
377 ms |
4504 KB |
Output is correct |
38 |
Correct |
331 ms |
2540 KB |
Output is correct |
39 |
Correct |
541 ms |
3692 KB |
Output is correct |
40 |
Correct |
636 ms |
3564 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 |
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 |
95 ms |
18284 KB |
Output is correct |
12 |
Correct |
97 ms |
18096 KB |
Output is correct |
13 |
Correct |
126 ms |
18028 KB |
Output is correct |
14 |
Correct |
192 ms |
18028 KB |
Output is correct |
15 |
Correct |
111 ms |
18156 KB |
Output is correct |
16 |
Correct |
182 ms |
18028 KB |
Output is correct |
17 |
Correct |
168 ms |
18028 KB |
Output is correct |
18 |
Correct |
82 ms |
18156 KB |
Output is correct |
19 |
Correct |
88 ms |
17844 KB |
Output is correct |
20 |
Correct |
98 ms |
18028 KB |
Output is correct |
21 |
Correct |
140 ms |
18156 KB |
Output is correct |
22 |
Correct |
198 ms |
18028 KB |
Output is correct |
23 |
Correct |
105 ms |
17900 KB |
Output is correct |
24 |
Correct |
181 ms |
18028 KB |
Output is correct |
25 |
Correct |
162 ms |
18156 KB |
Output is correct |
26 |
Correct |
83 ms |
17828 KB |
Output is correct |
27 |
Correct |
94 ms |
18028 KB |
Output is correct |
28 |
Correct |
91 ms |
17900 KB |
Output is correct |
29 |
Correct |
126 ms |
18028 KB |
Output is correct |
30 |
Correct |
151 ms |
18028 KB |
Output is correct |
31 |
Correct |
97 ms |
17900 KB |
Output is correct |
32 |
Correct |
188 ms |
17968 KB |
Output is correct |
33 |
Correct |
170 ms |
17984 KB |
Output is correct |
34 |
Correct |
81 ms |
17900 KB |
Output is correct |
35 |
Correct |
143 ms |
18028 KB |
Output is correct |
36 |
Correct |
141 ms |
18028 KB |
Output is correct |
37 |
Correct |
144 ms |
18156 KB |
Output is correct |
38 |
Correct |
140 ms |
18028 KB |
Output is correct |
39 |
Correct |
136 ms |
18028 KB |
Output is correct |
40 |
Correct |
148 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 |
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 |
315 ms |
4408 KB |
Output is correct |
12 |
Correct |
335 ms |
4144 KB |
Output is correct |
13 |
Correct |
382 ms |
3308 KB |
Output is correct |
14 |
Correct |
549 ms |
3436 KB |
Output is correct |
15 |
Correct |
405 ms |
4392 KB |
Output is correct |
16 |
Correct |
492 ms |
3564 KB |
Output is correct |
17 |
Correct |
464 ms |
3692 KB |
Output is correct |
18 |
Correct |
256 ms |
5348 KB |
Output is correct |
19 |
Correct |
283 ms |
2412 KB |
Output is correct |
20 |
Correct |
347 ms |
4076 KB |
Output is correct |
21 |
Correct |
376 ms |
4616 KB |
Output is correct |
22 |
Correct |
397 ms |
4716 KB |
Output is correct |
23 |
Correct |
535 ms |
3692 KB |
Output is correct |
24 |
Correct |
814 ms |
3564 KB |
Output is correct |
25 |
Correct |
489 ms |
5484 KB |
Output is correct |
26 |
Correct |
664 ms |
4076 KB |
Output is correct |
27 |
Correct |
623 ms |
3948 KB |
Output is correct |
28 |
Correct |
278 ms |
6636 KB |
Output is correct |
29 |
Correct |
314 ms |
2564 KB |
Output is correct |
30 |
Correct |
415 ms |
4716 KB |
Output is correct |
31 |
Correct |
616 ms |
4588 KB |
Output is correct |
32 |
Correct |
836 ms |
4524 KB |
Output is correct |
33 |
Correct |
440 ms |
3436 KB |
Output is correct |
34 |
Correct |
714 ms |
3724 KB |
Output is correct |
35 |
Correct |
629 ms |
4076 KB |
Output is correct |
36 |
Correct |
279 ms |
2540 KB |
Output is correct |
37 |
Correct |
377 ms |
4504 KB |
Output is correct |
38 |
Correct |
331 ms |
2540 KB |
Output is correct |
39 |
Correct |
541 ms |
3692 KB |
Output is correct |
40 |
Correct |
636 ms |
3564 KB |
Output is correct |
41 |
Correct |
95 ms |
18284 KB |
Output is correct |
42 |
Correct |
97 ms |
18096 KB |
Output is correct |
43 |
Correct |
126 ms |
18028 KB |
Output is correct |
44 |
Correct |
192 ms |
18028 KB |
Output is correct |
45 |
Correct |
111 ms |
18156 KB |
Output is correct |
46 |
Correct |
182 ms |
18028 KB |
Output is correct |
47 |
Correct |
168 ms |
18028 KB |
Output is correct |
48 |
Correct |
82 ms |
18156 KB |
Output is correct |
49 |
Correct |
88 ms |
17844 KB |
Output is correct |
50 |
Correct |
98 ms |
18028 KB |
Output is correct |
51 |
Correct |
140 ms |
18156 KB |
Output is correct |
52 |
Correct |
198 ms |
18028 KB |
Output is correct |
53 |
Correct |
105 ms |
17900 KB |
Output is correct |
54 |
Correct |
181 ms |
18028 KB |
Output is correct |
55 |
Correct |
162 ms |
18156 KB |
Output is correct |
56 |
Correct |
83 ms |
17828 KB |
Output is correct |
57 |
Correct |
94 ms |
18028 KB |
Output is correct |
58 |
Correct |
91 ms |
17900 KB |
Output is correct |
59 |
Correct |
126 ms |
18028 KB |
Output is correct |
60 |
Correct |
151 ms |
18028 KB |
Output is correct |
61 |
Correct |
97 ms |
17900 KB |
Output is correct |
62 |
Correct |
188 ms |
17968 KB |
Output is correct |
63 |
Correct |
170 ms |
17984 KB |
Output is correct |
64 |
Correct |
81 ms |
17900 KB |
Output is correct |
65 |
Correct |
143 ms |
18028 KB |
Output is correct |
66 |
Correct |
141 ms |
18028 KB |
Output is correct |
67 |
Correct |
144 ms |
18156 KB |
Output is correct |
68 |
Correct |
140 ms |
18028 KB |
Output is correct |
69 |
Correct |
136 ms |
18028 KB |
Output is correct |
70 |
Correct |
148 ms |
18028 KB |
Output is correct |
71 |
Correct |
670 ms |
22968 KB |
Output is correct |
72 |
Correct |
676 ms |
23024 KB |
Output is correct |
73 |
Correct |
1345 ms |
21484 KB |
Output is correct |
74 |
Execution timed out |
2051 ms |
20856 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |