#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define psf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(),x.end()
#define lb(x,v) (lower_bound(all(x),v)-x.begin())
#define ub(x,v) (upper_bound(all(x),v)-x.begin())
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> iii;
typedef tuple<int,int,int,int> iiii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
mt19937 rng(time(0));
#define mod 1000000007
inline int add(int a,int b){
int r=a+b;
while(r>=mod)r-=mod;
while(r<0)r+=mod;
return r;
}
inline int mult(int a,int b){
return (int)(((ll)(a*b))%mod);
}
inline int rd(){
int x=0;
char ch=getchar_unlocked();
while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
x=(x<<3)+(x<<1)+(ch&15);
ch=getchar_unlocked();
}
return x;
}
#define maxn ((1<<20)+5)
int l,q,t[maxn],super[maxn],sub[maxn];
char s[maxn];
int main(){
sf("%d%d",&l,&q);
sf(" %s",&s);
for(int i=0;i<(1<<l);++i){
t[i]=s[i]-'0';
sub[i]=super[i]=t[i];
}
for(int i=0;i<l;++i){
for(int j=0;j<(1<<l);++j){
if(j&(1<<i))sub[j]+=sub[j^(1<<i)];
}
}
for(int i=0;i<l;++i){
for(int j=(1<<l)-1;j>=0;--j){
if((j&(1<<i))==0)super[j]+=super[j^(1<<i)];
}
}
while(q--){
sf(" %s",&s);
int a=0,b=0,c=0;
for(int i=0;i<l;++i){
if(s[i]=='0')++a;
else if(s[i]=='1')++b;
else ++c;
}
if(c<=6){
int ans=0;
for(int i=0;i<(1<<c);++i){
int num=0;
int m=i;
for(int i=0;i<l;++i){
num<<=1;
if(s[i]=='1')++num;
else if(s[i]=='?'){
num+=m&1;
m>>=1;
}
}
ans+=t[num];
}
pf("%d\n",ans);
}
else if(a<=6){
int ans=0;
int m=0;
for(int i=0;i<l;++i){
if(s[i]=='1')m^=(1<<l-i-1);
}
for(int i=0;i<(1<<a);++i){
int nm=m,t=i,tot=0;
for(int j=0;j<l;++j){
if(s[j]=='0'){
nm^=(t&1)*(1<<l-j-1);
tot+=t&1;
t>>=1;
}
}
ans+=super[nm]*(tot%2?-1:1);
}
pf("%d\n",ans);
}
else{
int ans=0;
int m=0;
for(int i=0;i<l;++i){
if(s[i]=='?')m^=(1<<l-i-1);
}
for(int i=0;i<(1<<b);++i){
int nm=m,t=i,tot=0;
for(int j=0;j<l;++j){
if(s[j]=='1'){
nm^=(t&1)*(1<<l-j-1);
tot+=t&1;
t>>=1;
}
}
ans+=sub[nm]*((b-tot)%2?-1:1);
}
pf("%d\n",ans);
}
}
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:69:8: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1048581]' [-Wformat=]
69 | sf(" %s",&s);
| ~^ ~~
| | |
| | char (*)[1048581]
| char*
snake_escaping.cpp:85:9: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1048581]' [-Wformat=]
85 | sf(" %s",&s);
| ~^ ~~
| | |
| | char (*)[1048581]
| char*
snake_escaping.cpp:113:28: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
113 | if(s[i]=='1')m^=(1<<l-i-1);
| ~~~^~
snake_escaping.cpp:119:24: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
119 | nm^=(t&1)*(1<<l-j-1);
| ~~~^~
snake_escaping.cpp:132:28: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
132 | if(s[i]=='?')m^=(1<<l-i-1);
| ~~~^~
snake_escaping.cpp:138:24: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
138 | nm^=(t&1)*(1<<l-j-1);
| ~~~^~
snake_escaping.cpp:68:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | sf("%d%d",&l,&q);
| ^
snake_escaping.cpp:69:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | sf(" %s",&s);
| ^
snake_escaping.cpp:85:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | sf(" %s",&s);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
633 ms |
15104 KB |
Output is correct |
12 |
Correct |
681 ms |
14668 KB |
Output is correct |
13 |
Correct |
518 ms |
14096 KB |
Output is correct |
14 |
Correct |
549 ms |
14040 KB |
Output is correct |
15 |
Correct |
1149 ms |
15108 KB |
Output is correct |
16 |
Correct |
669 ms |
14204 KB |
Output is correct |
17 |
Correct |
661 ms |
14156 KB |
Output is correct |
18 |
Correct |
204 ms |
16100 KB |
Output is correct |
19 |
Correct |
248 ms |
12980 KB |
Output is correct |
20 |
Correct |
583 ms |
14796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
633 ms |
15104 KB |
Output is correct |
12 |
Correct |
681 ms |
14668 KB |
Output is correct |
13 |
Correct |
518 ms |
14096 KB |
Output is correct |
14 |
Correct |
549 ms |
14040 KB |
Output is correct |
15 |
Correct |
1149 ms |
15108 KB |
Output is correct |
16 |
Correct |
669 ms |
14204 KB |
Output is correct |
17 |
Correct |
661 ms |
14156 KB |
Output is correct |
18 |
Correct |
204 ms |
16100 KB |
Output is correct |
19 |
Correct |
248 ms |
12980 KB |
Output is correct |
20 |
Correct |
583 ms |
14796 KB |
Output is correct |
21 |
Correct |
318 ms |
18084 KB |
Output is correct |
22 |
Correct |
1056 ms |
18200 KB |
Output is correct |
23 |
Correct |
817 ms |
17348 KB |
Output is correct |
24 |
Correct |
836 ms |
17168 KB |
Output is correct |
25 |
Correct |
475 ms |
19244 KB |
Output is correct |
26 |
Correct |
998 ms |
17744 KB |
Output is correct |
27 |
Correct |
920 ms |
17540 KB |
Output is correct |
28 |
Correct |
240 ms |
20056 KB |
Output is correct |
29 |
Correct |
289 ms |
16124 KB |
Output is correct |
30 |
Correct |
636 ms |
18252 KB |
Output is correct |
31 |
Correct |
1586 ms |
18084 KB |
Output is correct |
32 |
Correct |
1085 ms |
18152 KB |
Output is correct |
33 |
Correct |
606 ms |
17012 KB |
Output is correct |
34 |
Correct |
852 ms |
17108 KB |
Output is correct |
35 |
Correct |
904 ms |
17596 KB |
Output is correct |
36 |
Correct |
223 ms |
16084 KB |
Output is correct |
37 |
Correct |
1383 ms |
18160 KB |
Output is correct |
38 |
Correct |
319 ms |
16132 KB |
Output is correct |
39 |
Correct |
846 ms |
17292 KB |
Output is correct |
40 |
Correct |
835 ms |
17128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
73 ms |
15924 KB |
Output is correct |
12 |
Correct |
85 ms |
15880 KB |
Output is correct |
13 |
Correct |
114 ms |
15756 KB |
Output is correct |
14 |
Correct |
147 ms |
15784 KB |
Output is correct |
15 |
Correct |
95 ms |
15976 KB |
Output is correct |
16 |
Correct |
160 ms |
15912 KB |
Output is correct |
17 |
Correct |
158 ms |
15944 KB |
Output is correct |
18 |
Correct |
73 ms |
16088 KB |
Output is correct |
19 |
Correct |
71 ms |
15908 KB |
Output is correct |
20 |
Correct |
73 ms |
15908 KB |
Output is correct |
21 |
Correct |
126 ms |
15920 KB |
Output is correct |
22 |
Correct |
209 ms |
15796 KB |
Output is correct |
23 |
Correct |
104 ms |
15792 KB |
Output is correct |
24 |
Correct |
158 ms |
15784 KB |
Output is correct |
25 |
Correct |
140 ms |
15820 KB |
Output is correct |
26 |
Correct |
55 ms |
15692 KB |
Output is correct |
27 |
Correct |
71 ms |
15844 KB |
Output is correct |
28 |
Correct |
68 ms |
15704 KB |
Output is correct |
29 |
Correct |
119 ms |
15772 KB |
Output is correct |
30 |
Correct |
159 ms |
15800 KB |
Output is correct |
31 |
Correct |
93 ms |
15756 KB |
Output is correct |
32 |
Correct |
163 ms |
16008 KB |
Output is correct |
33 |
Correct |
154 ms |
15812 KB |
Output is correct |
34 |
Correct |
55 ms |
15668 KB |
Output is correct |
35 |
Correct |
115 ms |
15760 KB |
Output is correct |
36 |
Correct |
125 ms |
15912 KB |
Output is correct |
37 |
Correct |
118 ms |
15804 KB |
Output is correct |
38 |
Correct |
131 ms |
15840 KB |
Output is correct |
39 |
Correct |
118 ms |
15820 KB |
Output is correct |
40 |
Correct |
130 ms |
16044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Correct |
2 ms |
352 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
352 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
633 ms |
15104 KB |
Output is correct |
12 |
Correct |
681 ms |
14668 KB |
Output is correct |
13 |
Correct |
518 ms |
14096 KB |
Output is correct |
14 |
Correct |
549 ms |
14040 KB |
Output is correct |
15 |
Correct |
1149 ms |
15108 KB |
Output is correct |
16 |
Correct |
669 ms |
14204 KB |
Output is correct |
17 |
Correct |
661 ms |
14156 KB |
Output is correct |
18 |
Correct |
204 ms |
16100 KB |
Output is correct |
19 |
Correct |
248 ms |
12980 KB |
Output is correct |
20 |
Correct |
583 ms |
14796 KB |
Output is correct |
21 |
Correct |
318 ms |
18084 KB |
Output is correct |
22 |
Correct |
1056 ms |
18200 KB |
Output is correct |
23 |
Correct |
817 ms |
17348 KB |
Output is correct |
24 |
Correct |
836 ms |
17168 KB |
Output is correct |
25 |
Correct |
475 ms |
19244 KB |
Output is correct |
26 |
Correct |
998 ms |
17744 KB |
Output is correct |
27 |
Correct |
920 ms |
17540 KB |
Output is correct |
28 |
Correct |
240 ms |
20056 KB |
Output is correct |
29 |
Correct |
289 ms |
16124 KB |
Output is correct |
30 |
Correct |
636 ms |
18252 KB |
Output is correct |
31 |
Correct |
1586 ms |
18084 KB |
Output is correct |
32 |
Correct |
1085 ms |
18152 KB |
Output is correct |
33 |
Correct |
606 ms |
17012 KB |
Output is correct |
34 |
Correct |
852 ms |
17108 KB |
Output is correct |
35 |
Correct |
904 ms |
17596 KB |
Output is correct |
36 |
Correct |
223 ms |
16084 KB |
Output is correct |
37 |
Correct |
1383 ms |
18160 KB |
Output is correct |
38 |
Correct |
319 ms |
16132 KB |
Output is correct |
39 |
Correct |
846 ms |
17292 KB |
Output is correct |
40 |
Correct |
835 ms |
17128 KB |
Output is correct |
41 |
Correct |
73 ms |
15924 KB |
Output is correct |
42 |
Correct |
85 ms |
15880 KB |
Output is correct |
43 |
Correct |
114 ms |
15756 KB |
Output is correct |
44 |
Correct |
147 ms |
15784 KB |
Output is correct |
45 |
Correct |
95 ms |
15976 KB |
Output is correct |
46 |
Correct |
160 ms |
15912 KB |
Output is correct |
47 |
Correct |
158 ms |
15944 KB |
Output is correct |
48 |
Correct |
73 ms |
16088 KB |
Output is correct |
49 |
Correct |
71 ms |
15908 KB |
Output is correct |
50 |
Correct |
73 ms |
15908 KB |
Output is correct |
51 |
Correct |
126 ms |
15920 KB |
Output is correct |
52 |
Correct |
209 ms |
15796 KB |
Output is correct |
53 |
Correct |
104 ms |
15792 KB |
Output is correct |
54 |
Correct |
158 ms |
15784 KB |
Output is correct |
55 |
Correct |
140 ms |
15820 KB |
Output is correct |
56 |
Correct |
55 ms |
15692 KB |
Output is correct |
57 |
Correct |
71 ms |
15844 KB |
Output is correct |
58 |
Correct |
68 ms |
15704 KB |
Output is correct |
59 |
Correct |
119 ms |
15772 KB |
Output is correct |
60 |
Correct |
159 ms |
15800 KB |
Output is correct |
61 |
Correct |
93 ms |
15756 KB |
Output is correct |
62 |
Correct |
163 ms |
16008 KB |
Output is correct |
63 |
Correct |
154 ms |
15812 KB |
Output is correct |
64 |
Correct |
55 ms |
15668 KB |
Output is correct |
65 |
Correct |
115 ms |
15760 KB |
Output is correct |
66 |
Correct |
125 ms |
15912 KB |
Output is correct |
67 |
Correct |
118 ms |
15804 KB |
Output is correct |
68 |
Correct |
131 ms |
15840 KB |
Output is correct |
69 |
Correct |
118 ms |
15820 KB |
Output is correct |
70 |
Correct |
130 ms |
16044 KB |
Output is correct |
71 |
Correct |
550 ms |
40128 KB |
Output is correct |
72 |
Correct |
698 ms |
40240 KB |
Output is correct |
73 |
Correct |
1476 ms |
38780 KB |
Output is correct |
74 |
Execution timed out |
2015 ms |
39348 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |