#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;
vi apos,bpos,cpos;
for(int i=0;i<l;++i){
if(s[i]=='0')++a,apos.pb(l-i-1);
else if(s[i]=='1')++b,bpos.pb(l-i-1);
else ++c,cpos.pb(l-i-1);
}
if(c<=6){
int ans=0,m=0;
for(int i:bpos)m^=1<<i;
for(int i=0;i<(1<<c);++i){
int nm=m,ti=i;
for(int j=0;j<c;++j){
nm^=(ti&1)<<cpos[j];
ti>>=1;
}
ans+=t[nm];
}
pf("%d\n",ans);
}
else if(a<=6){
int ans=0;
int m=0;
for(int i:bpos)m^=1<<i;
for(int i=0;i<(1<<a);++i){
int nm=m,t=i,tot=0;
for(int j=0;j<a;++j){
nm^=(t&1)<<apos[j];
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:cpos)m^=1<<i;
for(int i=0;i<(1<<b);++i){
int nm=m,t=i,tot=0;
for(int j=0;j<b;++j){
nm^=(t&1)<<bpos[j];
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: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);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
686 ms |
4400 KB |
Output is correct |
12 |
Correct |
582 ms |
4076 KB |
Output is correct |
13 |
Correct |
587 ms |
3328 KB |
Output is correct |
14 |
Correct |
612 ms |
3428 KB |
Output is correct |
15 |
Correct |
804 ms |
4440 KB |
Output is correct |
16 |
Correct |
641 ms |
3564 KB |
Output is correct |
17 |
Correct |
633 ms |
3684 KB |
Output is correct |
18 |
Correct |
360 ms |
5388 KB |
Output is correct |
19 |
Correct |
523 ms |
2396 KB |
Output is correct |
20 |
Correct |
586 ms |
4080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
686 ms |
4400 KB |
Output is correct |
12 |
Correct |
582 ms |
4076 KB |
Output is correct |
13 |
Correct |
587 ms |
3328 KB |
Output is correct |
14 |
Correct |
612 ms |
3428 KB |
Output is correct |
15 |
Correct |
804 ms |
4440 KB |
Output is correct |
16 |
Correct |
641 ms |
3564 KB |
Output is correct |
17 |
Correct |
633 ms |
3684 KB |
Output is correct |
18 |
Correct |
360 ms |
5388 KB |
Output is correct |
19 |
Correct |
523 ms |
2396 KB |
Output is correct |
20 |
Correct |
586 ms |
4080 KB |
Output is correct |
21 |
Correct |
532 ms |
4524 KB |
Output is correct |
22 |
Correct |
734 ms |
4652 KB |
Output is correct |
23 |
Correct |
698 ms |
3768 KB |
Output is correct |
24 |
Correct |
686 ms |
3540 KB |
Output is correct |
25 |
Correct |
601 ms |
5516 KB |
Output is correct |
26 |
Correct |
716 ms |
3992 KB |
Output is correct |
27 |
Correct |
715 ms |
4012 KB |
Output is correct |
28 |
Correct |
350 ms |
6572 KB |
Output is correct |
29 |
Correct |
512 ms |
2508 KB |
Output is correct |
30 |
Correct |
613 ms |
4732 KB |
Output is correct |
31 |
Correct |
861 ms |
4652 KB |
Output is correct |
32 |
Correct |
737 ms |
4524 KB |
Output is correct |
33 |
Correct |
559 ms |
3452 KB |
Output is correct |
34 |
Correct |
671 ms |
3664 KB |
Output is correct |
35 |
Correct |
716 ms |
3908 KB |
Output is correct |
36 |
Correct |
357 ms |
2536 KB |
Output is correct |
37 |
Correct |
788 ms |
4608 KB |
Output is correct |
38 |
Correct |
529 ms |
2756 KB |
Output is correct |
39 |
Correct |
663 ms |
3700 KB |
Output is correct |
40 |
Correct |
661 ms |
3660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
76 ms |
14260 KB |
Output is correct |
12 |
Correct |
81 ms |
14176 KB |
Output is correct |
13 |
Correct |
96 ms |
14152 KB |
Output is correct |
14 |
Correct |
115 ms |
14132 KB |
Output is correct |
15 |
Correct |
86 ms |
14268 KB |
Output is correct |
16 |
Correct |
111 ms |
14184 KB |
Output is correct |
17 |
Correct |
111 ms |
14184 KB |
Output is correct |
18 |
Correct |
65 ms |
14364 KB |
Output is correct |
19 |
Correct |
82 ms |
14032 KB |
Output is correct |
20 |
Correct |
81 ms |
14272 KB |
Output is correct |
21 |
Correct |
94 ms |
14196 KB |
Output is correct |
22 |
Correct |
127 ms |
14172 KB |
Output is correct |
23 |
Correct |
81 ms |
14148 KB |
Output is correct |
24 |
Correct |
104 ms |
14092 KB |
Output is correct |
25 |
Correct |
110 ms |
14120 KB |
Output is correct |
26 |
Correct |
65 ms |
14036 KB |
Output is correct |
27 |
Correct |
81 ms |
14204 KB |
Output is correct |
28 |
Correct |
81 ms |
14192 KB |
Output is correct |
29 |
Correct |
95 ms |
14132 KB |
Output is correct |
30 |
Correct |
114 ms |
14140 KB |
Output is correct |
31 |
Correct |
82 ms |
14144 KB |
Output is correct |
32 |
Correct |
120 ms |
14176 KB |
Output is correct |
33 |
Correct |
119 ms |
14128 KB |
Output is correct |
34 |
Correct |
64 ms |
14096 KB |
Output is correct |
35 |
Correct |
98 ms |
14104 KB |
Output is correct |
36 |
Correct |
99 ms |
14172 KB |
Output is correct |
37 |
Correct |
98 ms |
14144 KB |
Output is correct |
38 |
Correct |
101 ms |
14108 KB |
Output is correct |
39 |
Correct |
107 ms |
14148 KB |
Output is correct |
40 |
Correct |
100 ms |
14156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
686 ms |
4400 KB |
Output is correct |
12 |
Correct |
582 ms |
4076 KB |
Output is correct |
13 |
Correct |
587 ms |
3328 KB |
Output is correct |
14 |
Correct |
612 ms |
3428 KB |
Output is correct |
15 |
Correct |
804 ms |
4440 KB |
Output is correct |
16 |
Correct |
641 ms |
3564 KB |
Output is correct |
17 |
Correct |
633 ms |
3684 KB |
Output is correct |
18 |
Correct |
360 ms |
5388 KB |
Output is correct |
19 |
Correct |
523 ms |
2396 KB |
Output is correct |
20 |
Correct |
586 ms |
4080 KB |
Output is correct |
21 |
Correct |
532 ms |
4524 KB |
Output is correct |
22 |
Correct |
734 ms |
4652 KB |
Output is correct |
23 |
Correct |
698 ms |
3768 KB |
Output is correct |
24 |
Correct |
686 ms |
3540 KB |
Output is correct |
25 |
Correct |
601 ms |
5516 KB |
Output is correct |
26 |
Correct |
716 ms |
3992 KB |
Output is correct |
27 |
Correct |
715 ms |
4012 KB |
Output is correct |
28 |
Correct |
350 ms |
6572 KB |
Output is correct |
29 |
Correct |
512 ms |
2508 KB |
Output is correct |
30 |
Correct |
613 ms |
4732 KB |
Output is correct |
31 |
Correct |
861 ms |
4652 KB |
Output is correct |
32 |
Correct |
737 ms |
4524 KB |
Output is correct |
33 |
Correct |
559 ms |
3452 KB |
Output is correct |
34 |
Correct |
671 ms |
3664 KB |
Output is correct |
35 |
Correct |
716 ms |
3908 KB |
Output is correct |
36 |
Correct |
357 ms |
2536 KB |
Output is correct |
37 |
Correct |
788 ms |
4608 KB |
Output is correct |
38 |
Correct |
529 ms |
2756 KB |
Output is correct |
39 |
Correct |
663 ms |
3700 KB |
Output is correct |
40 |
Correct |
661 ms |
3660 KB |
Output is correct |
41 |
Correct |
76 ms |
14260 KB |
Output is correct |
42 |
Correct |
81 ms |
14176 KB |
Output is correct |
43 |
Correct |
96 ms |
14152 KB |
Output is correct |
44 |
Correct |
115 ms |
14132 KB |
Output is correct |
45 |
Correct |
86 ms |
14268 KB |
Output is correct |
46 |
Correct |
111 ms |
14184 KB |
Output is correct |
47 |
Correct |
111 ms |
14184 KB |
Output is correct |
48 |
Correct |
65 ms |
14364 KB |
Output is correct |
49 |
Correct |
82 ms |
14032 KB |
Output is correct |
50 |
Correct |
81 ms |
14272 KB |
Output is correct |
51 |
Correct |
94 ms |
14196 KB |
Output is correct |
52 |
Correct |
127 ms |
14172 KB |
Output is correct |
53 |
Correct |
81 ms |
14148 KB |
Output is correct |
54 |
Correct |
104 ms |
14092 KB |
Output is correct |
55 |
Correct |
110 ms |
14120 KB |
Output is correct |
56 |
Correct |
65 ms |
14036 KB |
Output is correct |
57 |
Correct |
81 ms |
14204 KB |
Output is correct |
58 |
Correct |
81 ms |
14192 KB |
Output is correct |
59 |
Correct |
95 ms |
14132 KB |
Output is correct |
60 |
Correct |
114 ms |
14140 KB |
Output is correct |
61 |
Correct |
82 ms |
14144 KB |
Output is correct |
62 |
Correct |
120 ms |
14176 KB |
Output is correct |
63 |
Correct |
119 ms |
14128 KB |
Output is correct |
64 |
Correct |
64 ms |
14096 KB |
Output is correct |
65 |
Correct |
98 ms |
14104 KB |
Output is correct |
66 |
Correct |
99 ms |
14172 KB |
Output is correct |
67 |
Correct |
98 ms |
14144 KB |
Output is correct |
68 |
Correct |
101 ms |
14108 KB |
Output is correct |
69 |
Correct |
107 ms |
14148 KB |
Output is correct |
70 |
Correct |
100 ms |
14156 KB |
Output is correct |
71 |
Correct |
761 ms |
18696 KB |
Output is correct |
72 |
Correct |
825 ms |
18832 KB |
Output is correct |
73 |
Correct |
1046 ms |
17252 KB |
Output is correct |
74 |
Correct |
1353 ms |
17600 KB |
Output is correct |
75 |
Correct |
846 ms |
41228 KB |
Output is correct |
76 |
Correct |
1484 ms |
39416 KB |
Output is correct |
77 |
Correct |
1389 ms |
39304 KB |
Output is correct |
78 |
Correct |
504 ms |
43220 KB |
Output is correct |
79 |
Correct |
758 ms |
37252 KB |
Output is correct |
80 |
Correct |
807 ms |
40352 KB |
Output is correct |
81 |
Correct |
1091 ms |
40176 KB |
Output is correct |
82 |
Correct |
1282 ms |
39264 KB |
Output is correct |
83 |
Correct |
845 ms |
38348 KB |
Output is correct |
84 |
Correct |
1286 ms |
39276 KB |
Output is correct |
85 |
Correct |
1408 ms |
39656 KB |
Output is correct |
86 |
Correct |
517 ms |
37292 KB |
Output is correct |
87 |
Correct |
762 ms |
40312 KB |
Output is correct |
88 |
Correct |
771 ms |
37316 KB |
Output is correct |
89 |
Correct |
1043 ms |
38792 KB |
Output is correct |
90 |
Correct |
1236 ms |
39196 KB |
Output is correct |
91 |
Correct |
874 ms |
38424 KB |
Output is correct |
92 |
Correct |
1587 ms |
39556 KB |
Output is correct |
93 |
Correct |
1421 ms |
39408 KB |
Output is correct |
94 |
Correct |
502 ms |
37244 KB |
Output is correct |
95 |
Correct |
1215 ms |
39328 KB |
Output is correct |
96 |
Correct |
1210 ms |
39340 KB |
Output is correct |
97 |
Correct |
1216 ms |
39280 KB |
Output is correct |
98 |
Correct |
1190 ms |
39376 KB |
Output is correct |
99 |
Correct |
1188 ms |
39308 KB |
Output is correct |
100 |
Correct |
1186 ms |
39324 KB |
Output is correct |