#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=(1LL<<21);
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,q,L,f[N],b[N],bcnt[N],u[N],p0,p1,p2,res;
string s;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q>>s;
L=(1<<n);
REP(i,L){
f[i]=b[i]=u[i]=s[i]-'0';
bcnt[i]=bcnt[i>>1]+(i&1);
}
for(int i=1;i<L;i<<=1){
REP(j,L){
if(i&j)f[j]+=f[i^j],b[i^j]+=b[j];
}
}
while(q--){
cin>>s;
p0=p1=p2=res=0;
REP(i,n){
if(s[n-i-1]=='0')p0|=(1<<i);
else if(s[n-i-1]=='1')p1|=(1<<i);
else p2|=(1<<i);
}
if(bcnt[p0]<=6){
for(int bit=p0;;bit=(bit-1)&p0){
if(bcnt[bit]&1)res-=b[bit|p1];
else res+=b[bit|p1];
if(!bit)break;
}
}else if(bcnt[p1]<=6){
for(int bit=p1;;bit=(bit-1)&p1){
if(bcnt[bit^p1]&1)res-=f[bit|p2];
else res+=f[bit|p2];
if(!bit)break;
}
}else{
for(int bit=p2;;bit=(bit-1)&p2){
res+=u[p1|bit];
if(!bit)break;
}
}
cout<<res<<"\n";
}
return 0;
}
# |
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 |
227 ms |
4588 KB |
Output is correct |
12 |
Correct |
290 ms |
4204 KB |
Output is correct |
13 |
Correct |
309 ms |
3436 KB |
Output is correct |
14 |
Correct |
278 ms |
3436 KB |
Output is correct |
15 |
Correct |
243 ms |
4460 KB |
Output is correct |
16 |
Correct |
270 ms |
3692 KB |
Output is correct |
17 |
Correct |
291 ms |
3692 KB |
Output is correct |
18 |
Correct |
198 ms |
5484 KB |
Output is correct |
19 |
Correct |
287 ms |
2412 KB |
Output is correct |
20 |
Correct |
254 ms |
4204 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 |
227 ms |
4588 KB |
Output is correct |
12 |
Correct |
290 ms |
4204 KB |
Output is correct |
13 |
Correct |
309 ms |
3436 KB |
Output is correct |
14 |
Correct |
278 ms |
3436 KB |
Output is correct |
15 |
Correct |
243 ms |
4460 KB |
Output is correct |
16 |
Correct |
270 ms |
3692 KB |
Output is correct |
17 |
Correct |
291 ms |
3692 KB |
Output is correct |
18 |
Correct |
198 ms |
5484 KB |
Output is correct |
19 |
Correct |
287 ms |
2412 KB |
Output is correct |
20 |
Correct |
254 ms |
4204 KB |
Output is correct |
21 |
Correct |
256 ms |
4716 KB |
Output is correct |
22 |
Correct |
330 ms |
4844 KB |
Output is correct |
23 |
Correct |
429 ms |
3916 KB |
Output is correct |
24 |
Correct |
445 ms |
3820 KB |
Output is correct |
25 |
Correct |
323 ms |
5868 KB |
Output is correct |
26 |
Correct |
355 ms |
4204 KB |
Output is correct |
27 |
Correct |
345 ms |
4076 KB |
Output is correct |
28 |
Correct |
216 ms |
6784 KB |
Output is correct |
29 |
Correct |
395 ms |
2796 KB |
Output is correct |
30 |
Correct |
275 ms |
4844 KB |
Output is correct |
31 |
Correct |
315 ms |
4716 KB |
Output is correct |
32 |
Correct |
314 ms |
4716 KB |
Output is correct |
33 |
Correct |
275 ms |
3564 KB |
Output is correct |
34 |
Correct |
341 ms |
3692 KB |
Output is correct |
35 |
Correct |
348 ms |
4076 KB |
Output is correct |
36 |
Correct |
203 ms |
2668 KB |
Output is correct |
37 |
Correct |
253 ms |
4716 KB |
Output is correct |
38 |
Correct |
356 ms |
2796 KB |
Output is correct |
39 |
Correct |
318 ms |
3820 KB |
Output is correct |
40 |
Correct |
314 ms |
3820 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 |
76 ms |
34572 KB |
Output is correct |
12 |
Correct |
81 ms |
35600 KB |
Output is correct |
13 |
Correct |
97 ms |
35600 KB |
Output is correct |
14 |
Correct |
119 ms |
35540 KB |
Output is correct |
15 |
Correct |
81 ms |
35984 KB |
Output is correct |
16 |
Correct |
118 ms |
35216 KB |
Output is correct |
17 |
Correct |
108 ms |
35216 KB |
Output is correct |
18 |
Correct |
68 ms |
35344 KB |
Output is correct |
19 |
Correct |
79 ms |
35088 KB |
Output is correct |
20 |
Correct |
78 ms |
35216 KB |
Output is correct |
21 |
Correct |
93 ms |
35216 KB |
Output is correct |
22 |
Correct |
117 ms |
35116 KB |
Output is correct |
23 |
Correct |
79 ms |
35472 KB |
Output is correct |
24 |
Correct |
113 ms |
35472 KB |
Output is correct |
25 |
Correct |
108 ms |
35600 KB |
Output is correct |
26 |
Correct |
66 ms |
35344 KB |
Output is correct |
27 |
Correct |
79 ms |
35600 KB |
Output is correct |
28 |
Correct |
82 ms |
35344 KB |
Output is correct |
29 |
Correct |
93 ms |
35600 KB |
Output is correct |
30 |
Correct |
103 ms |
35652 KB |
Output is correct |
31 |
Correct |
82 ms |
35472 KB |
Output is correct |
32 |
Correct |
122 ms |
35600 KB |
Output is correct |
33 |
Correct |
106 ms |
35472 KB |
Output is correct |
34 |
Correct |
68 ms |
35344 KB |
Output is correct |
35 |
Correct |
96 ms |
35472 KB |
Output is correct |
36 |
Correct |
102 ms |
35472 KB |
Output is correct |
37 |
Correct |
98 ms |
35600 KB |
Output is correct |
38 |
Correct |
97 ms |
35472 KB |
Output is correct |
39 |
Correct |
98 ms |
35600 KB |
Output is correct |
40 |
Correct |
96 ms |
35472 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 |
227 ms |
4588 KB |
Output is correct |
12 |
Correct |
290 ms |
4204 KB |
Output is correct |
13 |
Correct |
309 ms |
3436 KB |
Output is correct |
14 |
Correct |
278 ms |
3436 KB |
Output is correct |
15 |
Correct |
243 ms |
4460 KB |
Output is correct |
16 |
Correct |
270 ms |
3692 KB |
Output is correct |
17 |
Correct |
291 ms |
3692 KB |
Output is correct |
18 |
Correct |
198 ms |
5484 KB |
Output is correct |
19 |
Correct |
287 ms |
2412 KB |
Output is correct |
20 |
Correct |
254 ms |
4204 KB |
Output is correct |
21 |
Correct |
256 ms |
4716 KB |
Output is correct |
22 |
Correct |
330 ms |
4844 KB |
Output is correct |
23 |
Correct |
429 ms |
3916 KB |
Output is correct |
24 |
Correct |
445 ms |
3820 KB |
Output is correct |
25 |
Correct |
323 ms |
5868 KB |
Output is correct |
26 |
Correct |
355 ms |
4204 KB |
Output is correct |
27 |
Correct |
345 ms |
4076 KB |
Output is correct |
28 |
Correct |
216 ms |
6784 KB |
Output is correct |
29 |
Correct |
395 ms |
2796 KB |
Output is correct |
30 |
Correct |
275 ms |
4844 KB |
Output is correct |
31 |
Correct |
315 ms |
4716 KB |
Output is correct |
32 |
Correct |
314 ms |
4716 KB |
Output is correct |
33 |
Correct |
275 ms |
3564 KB |
Output is correct |
34 |
Correct |
341 ms |
3692 KB |
Output is correct |
35 |
Correct |
348 ms |
4076 KB |
Output is correct |
36 |
Correct |
203 ms |
2668 KB |
Output is correct |
37 |
Correct |
253 ms |
4716 KB |
Output is correct |
38 |
Correct |
356 ms |
2796 KB |
Output is correct |
39 |
Correct |
318 ms |
3820 KB |
Output is correct |
40 |
Correct |
314 ms |
3820 KB |
Output is correct |
41 |
Correct |
76 ms |
34572 KB |
Output is correct |
42 |
Correct |
81 ms |
35600 KB |
Output is correct |
43 |
Correct |
97 ms |
35600 KB |
Output is correct |
44 |
Correct |
119 ms |
35540 KB |
Output is correct |
45 |
Correct |
81 ms |
35984 KB |
Output is correct |
46 |
Correct |
118 ms |
35216 KB |
Output is correct |
47 |
Correct |
108 ms |
35216 KB |
Output is correct |
48 |
Correct |
68 ms |
35344 KB |
Output is correct |
49 |
Correct |
79 ms |
35088 KB |
Output is correct |
50 |
Correct |
78 ms |
35216 KB |
Output is correct |
51 |
Correct |
93 ms |
35216 KB |
Output is correct |
52 |
Correct |
117 ms |
35116 KB |
Output is correct |
53 |
Correct |
79 ms |
35472 KB |
Output is correct |
54 |
Correct |
113 ms |
35472 KB |
Output is correct |
55 |
Correct |
108 ms |
35600 KB |
Output is correct |
56 |
Correct |
66 ms |
35344 KB |
Output is correct |
57 |
Correct |
79 ms |
35600 KB |
Output is correct |
58 |
Correct |
82 ms |
35344 KB |
Output is correct |
59 |
Correct |
93 ms |
35600 KB |
Output is correct |
60 |
Correct |
103 ms |
35652 KB |
Output is correct |
61 |
Correct |
82 ms |
35472 KB |
Output is correct |
62 |
Correct |
122 ms |
35600 KB |
Output is correct |
63 |
Correct |
106 ms |
35472 KB |
Output is correct |
64 |
Correct |
68 ms |
35344 KB |
Output is correct |
65 |
Correct |
96 ms |
35472 KB |
Output is correct |
66 |
Correct |
102 ms |
35472 KB |
Output is correct |
67 |
Correct |
98 ms |
35600 KB |
Output is correct |
68 |
Correct |
97 ms |
35472 KB |
Output is correct |
69 |
Correct |
98 ms |
35600 KB |
Output is correct |
70 |
Correct |
96 ms |
35472 KB |
Output is correct |
71 |
Correct |
454 ms |
40336 KB |
Output is correct |
72 |
Correct |
531 ms |
41432 KB |
Output is correct |
73 |
Correct |
853 ms |
39984 KB |
Output is correct |
74 |
Correct |
1290 ms |
40420 KB |
Output is correct |
75 |
Correct |
500 ms |
42256 KB |
Output is correct |
76 |
Correct |
1319 ms |
42512 KB |
Output is correct |
77 |
Correct |
1065 ms |
39184 KB |
Output is correct |
78 |
Correct |
304 ms |
42896 KB |
Output is correct |
79 |
Correct |
496 ms |
36880 KB |
Output is correct |
80 |
Correct |
475 ms |
40208 KB |
Output is correct |
81 |
Correct |
766 ms |
39824 KB |
Output is correct |
82 |
Correct |
1274 ms |
39056 KB |
Output is correct |
83 |
Correct |
487 ms |
38160 KB |
Output is correct |
84 |
Correct |
1191 ms |
38928 KB |
Output is correct |
85 |
Correct |
1084 ms |
39292 KB |
Output is correct |
86 |
Correct |
279 ms |
36880 KB |
Output is correct |
87 |
Correct |
482 ms |
39924 KB |
Output is correct |
88 |
Correct |
575 ms |
36880 KB |
Output is correct |
89 |
Correct |
782 ms |
38672 KB |
Output is correct |
90 |
Correct |
958 ms |
38928 KB |
Output is correct |
91 |
Correct |
585 ms |
38032 KB |
Output is correct |
92 |
Correct |
1337 ms |
39632 KB |
Output is correct |
93 |
Correct |
1074 ms |
38720 KB |
Output is correct |
94 |
Correct |
268 ms |
36624 KB |
Output is correct |
95 |
Correct |
898 ms |
38672 KB |
Output is correct |
96 |
Correct |
902 ms |
38688 KB |
Output is correct |
97 |
Correct |
896 ms |
38600 KB |
Output is correct |
98 |
Correct |
902 ms |
38544 KB |
Output is correct |
99 |
Correct |
900 ms |
38652 KB |
Output is correct |
100 |
Correct |
890 ms |
38672 KB |
Output is correct |