//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define pc __builtin_popcount
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=20;
int n,q,dp[2][1<<N];
string s;
int main(){
FastIO
cin >> n >> q >> s;
for(int i=0;i<1<<n;i++) dp[0][i]=dp[1][i]=s[i]-'0';
for(int i=0;i<n;i++)
for(int mask=0;mask<1<<n;mask++)
if(!(mask>>i & 1))
dp[0][mask]+=dp[0][mask^(1<<i)];
for(int i=0;i<n;i++)
for(int mask=(1<<n)-1;~mask;mask--)
if(mask>>i & 1)
dp[1][mask]+=dp[1][mask^(1<<i)];
while(q--){
int ans=0,msk0=0,msk1=0,msk2=0;
string t;cin >> t;
for(char c: t){
msk0<<=1;msk1<<=1;msk2<<=1;
if(c=='0') msk0++;
else if(c=='1') msk1++;
else msk2++;
}
if(pc(msk0)<=6){
for(int mask=msk0;;mask=(mask-1)&msk0){
ans+=(pc(mask)&1?-1:1)*dp[0][mask^msk1];
if(!mask) break;
}
}
else if(pc(msk1)<=6){
for(int mask=msk1;;mask=(mask-1)&msk1){
ans+=((pc(msk1)-pc(mask))&1?-1:1)*dp[1][mask^msk2];
if(!mask) break;
}
}
else{
for(int mask=msk2;;mask=(mask-1)&msk2){
ans+=s[mask|msk1]-'0';
if(!mask) break;
}
}
cout << ans << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
146 ms |
15004 KB |
Output is correct |
12 |
Correct |
212 ms |
14676 KB |
Output is correct |
13 |
Correct |
232 ms |
13912 KB |
Output is correct |
14 |
Correct |
180 ms |
14160 KB |
Output is correct |
15 |
Correct |
157 ms |
15208 KB |
Output is correct |
16 |
Correct |
181 ms |
14164 KB |
Output is correct |
17 |
Correct |
222 ms |
14164 KB |
Output is correct |
18 |
Correct |
108 ms |
16208 KB |
Output is correct |
19 |
Correct |
234 ms |
13136 KB |
Output is correct |
20 |
Correct |
152 ms |
14664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
146 ms |
15004 KB |
Output is correct |
12 |
Correct |
212 ms |
14676 KB |
Output is correct |
13 |
Correct |
232 ms |
13912 KB |
Output is correct |
14 |
Correct |
180 ms |
14160 KB |
Output is correct |
15 |
Correct |
157 ms |
15208 KB |
Output is correct |
16 |
Correct |
181 ms |
14164 KB |
Output is correct |
17 |
Correct |
222 ms |
14164 KB |
Output is correct |
18 |
Correct |
108 ms |
16208 KB |
Output is correct |
19 |
Correct |
234 ms |
13136 KB |
Output is correct |
20 |
Correct |
152 ms |
14664 KB |
Output is correct |
21 |
Correct |
174 ms |
18004 KB |
Output is correct |
22 |
Correct |
218 ms |
18248 KB |
Output is correct |
23 |
Correct |
360 ms |
17408 KB |
Output is correct |
24 |
Correct |
265 ms |
17168 KB |
Output is correct |
25 |
Correct |
189 ms |
19028 KB |
Output is correct |
26 |
Correct |
213 ms |
17492 KB |
Output is correct |
27 |
Correct |
248 ms |
17488 KB |
Output is correct |
28 |
Correct |
113 ms |
20052 KB |
Output is correct |
29 |
Correct |
314 ms |
16212 KB |
Output is correct |
30 |
Correct |
169 ms |
18288 KB |
Output is correct |
31 |
Correct |
209 ms |
18084 KB |
Output is correct |
32 |
Correct |
213 ms |
18028 KB |
Output is correct |
33 |
Correct |
169 ms |
16976 KB |
Output is correct |
34 |
Correct |
246 ms |
17080 KB |
Output is correct |
35 |
Correct |
242 ms |
17488 KB |
Output is correct |
36 |
Correct |
105 ms |
16208 KB |
Output is correct |
37 |
Correct |
143 ms |
18000 KB |
Output is correct |
38 |
Correct |
282 ms |
16156 KB |
Output is correct |
39 |
Correct |
213 ms |
17236 KB |
Output is correct |
40 |
Correct |
219 ms |
17236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
45 ms |
12096 KB |
Output is correct |
12 |
Correct |
47 ms |
12020 KB |
Output is correct |
13 |
Correct |
53 ms |
11940 KB |
Output is correct |
14 |
Correct |
63 ms |
11964 KB |
Output is correct |
15 |
Correct |
48 ms |
12148 KB |
Output is correct |
16 |
Correct |
59 ms |
11856 KB |
Output is correct |
17 |
Correct |
60 ms |
11852 KB |
Output is correct |
18 |
Correct |
41 ms |
12020 KB |
Output is correct |
19 |
Correct |
45 ms |
11764 KB |
Output is correct |
20 |
Correct |
45 ms |
12024 KB |
Output is correct |
21 |
Correct |
52 ms |
12020 KB |
Output is correct |
22 |
Correct |
60 ms |
11912 KB |
Output is correct |
23 |
Correct |
48 ms |
11856 KB |
Output is correct |
24 |
Correct |
59 ms |
12016 KB |
Output is correct |
25 |
Correct |
55 ms |
12016 KB |
Output is correct |
26 |
Correct |
41 ms |
11760 KB |
Output is correct |
27 |
Correct |
45 ms |
11972 KB |
Output is correct |
28 |
Correct |
47 ms |
11764 KB |
Output is correct |
29 |
Correct |
55 ms |
11860 KB |
Output is correct |
30 |
Correct |
52 ms |
12028 KB |
Output is correct |
31 |
Correct |
49 ms |
12016 KB |
Output is correct |
32 |
Correct |
65 ms |
12020 KB |
Output is correct |
33 |
Correct |
56 ms |
12020 KB |
Output is correct |
34 |
Correct |
43 ms |
11760 KB |
Output is correct |
35 |
Correct |
51 ms |
12020 KB |
Output is correct |
36 |
Correct |
52 ms |
11836 KB |
Output is correct |
37 |
Correct |
52 ms |
12020 KB |
Output is correct |
38 |
Correct |
52 ms |
12020 KB |
Output is correct |
39 |
Correct |
52 ms |
12272 KB |
Output is correct |
40 |
Correct |
56 ms |
11952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
146 ms |
15004 KB |
Output is correct |
12 |
Correct |
212 ms |
14676 KB |
Output is correct |
13 |
Correct |
232 ms |
13912 KB |
Output is correct |
14 |
Correct |
180 ms |
14160 KB |
Output is correct |
15 |
Correct |
157 ms |
15208 KB |
Output is correct |
16 |
Correct |
181 ms |
14164 KB |
Output is correct |
17 |
Correct |
222 ms |
14164 KB |
Output is correct |
18 |
Correct |
108 ms |
16208 KB |
Output is correct |
19 |
Correct |
234 ms |
13136 KB |
Output is correct |
20 |
Correct |
152 ms |
14664 KB |
Output is correct |
21 |
Correct |
174 ms |
18004 KB |
Output is correct |
22 |
Correct |
218 ms |
18248 KB |
Output is correct |
23 |
Correct |
360 ms |
17408 KB |
Output is correct |
24 |
Correct |
265 ms |
17168 KB |
Output is correct |
25 |
Correct |
189 ms |
19028 KB |
Output is correct |
26 |
Correct |
213 ms |
17492 KB |
Output is correct |
27 |
Correct |
248 ms |
17488 KB |
Output is correct |
28 |
Correct |
113 ms |
20052 KB |
Output is correct |
29 |
Correct |
314 ms |
16212 KB |
Output is correct |
30 |
Correct |
169 ms |
18288 KB |
Output is correct |
31 |
Correct |
209 ms |
18084 KB |
Output is correct |
32 |
Correct |
213 ms |
18028 KB |
Output is correct |
33 |
Correct |
169 ms |
16976 KB |
Output is correct |
34 |
Correct |
246 ms |
17080 KB |
Output is correct |
35 |
Correct |
242 ms |
17488 KB |
Output is correct |
36 |
Correct |
105 ms |
16208 KB |
Output is correct |
37 |
Correct |
143 ms |
18000 KB |
Output is correct |
38 |
Correct |
282 ms |
16156 KB |
Output is correct |
39 |
Correct |
213 ms |
17236 KB |
Output is correct |
40 |
Correct |
219 ms |
17236 KB |
Output is correct |
41 |
Correct |
45 ms |
12096 KB |
Output is correct |
42 |
Correct |
47 ms |
12020 KB |
Output is correct |
43 |
Correct |
53 ms |
11940 KB |
Output is correct |
44 |
Correct |
63 ms |
11964 KB |
Output is correct |
45 |
Correct |
48 ms |
12148 KB |
Output is correct |
46 |
Correct |
59 ms |
11856 KB |
Output is correct |
47 |
Correct |
60 ms |
11852 KB |
Output is correct |
48 |
Correct |
41 ms |
12020 KB |
Output is correct |
49 |
Correct |
45 ms |
11764 KB |
Output is correct |
50 |
Correct |
45 ms |
12024 KB |
Output is correct |
51 |
Correct |
52 ms |
12020 KB |
Output is correct |
52 |
Correct |
60 ms |
11912 KB |
Output is correct |
53 |
Correct |
48 ms |
11856 KB |
Output is correct |
54 |
Correct |
59 ms |
12016 KB |
Output is correct |
55 |
Correct |
55 ms |
12016 KB |
Output is correct |
56 |
Correct |
41 ms |
11760 KB |
Output is correct |
57 |
Correct |
45 ms |
11972 KB |
Output is correct |
58 |
Correct |
47 ms |
11764 KB |
Output is correct |
59 |
Correct |
55 ms |
11860 KB |
Output is correct |
60 |
Correct |
52 ms |
12028 KB |
Output is correct |
61 |
Correct |
49 ms |
12016 KB |
Output is correct |
62 |
Correct |
65 ms |
12020 KB |
Output is correct |
63 |
Correct |
56 ms |
12020 KB |
Output is correct |
64 |
Correct |
43 ms |
11760 KB |
Output is correct |
65 |
Correct |
51 ms |
12020 KB |
Output is correct |
66 |
Correct |
52 ms |
11836 KB |
Output is correct |
67 |
Correct |
52 ms |
12020 KB |
Output is correct |
68 |
Correct |
52 ms |
12020 KB |
Output is correct |
69 |
Correct |
52 ms |
12272 KB |
Output is correct |
70 |
Correct |
56 ms |
11952 KB |
Output is correct |
71 |
Correct |
270 ms |
36180 KB |
Output is correct |
72 |
Correct |
271 ms |
36340 KB |
Output is correct |
73 |
Correct |
400 ms |
34808 KB |
Output is correct |
74 |
Correct |
530 ms |
35316 KB |
Output is correct |
75 |
Correct |
327 ms |
37296 KB |
Output is correct |
76 |
Correct |
545 ms |
35572 KB |
Output is correct |
77 |
Correct |
438 ms |
35388 KB |
Output is correct |
78 |
Correct |
184 ms |
39152 KB |
Output is correct |
79 |
Correct |
247 ms |
33264 KB |
Output is correct |
80 |
Correct |
266 ms |
36340 KB |
Output is correct |
81 |
Correct |
393 ms |
36276 KB |
Output is correct |
82 |
Correct |
538 ms |
35316 KB |
Output is correct |
83 |
Correct |
291 ms |
34392 KB |
Output is correct |
84 |
Correct |
473 ms |
35304 KB |
Output is correct |
85 |
Correct |
429 ms |
35312 KB |
Output is correct |
86 |
Correct |
180 ms |
33268 KB |
Output is correct |
87 |
Correct |
233 ms |
36340 KB |
Output is correct |
88 |
Correct |
269 ms |
33268 KB |
Output is correct |
89 |
Correct |
380 ms |
34804 KB |
Output is correct |
90 |
Correct |
369 ms |
35136 KB |
Output is correct |
91 |
Correct |
339 ms |
34504 KB |
Output is correct |
92 |
Correct |
504 ms |
35632 KB |
Output is correct |
93 |
Correct |
421 ms |
35564 KB |
Output is correct |
94 |
Correct |
166 ms |
33264 KB |
Output is correct |
95 |
Correct |
431 ms |
35312 KB |
Output is correct |
96 |
Correct |
369 ms |
35320 KB |
Output is correct |
97 |
Correct |
391 ms |
35316 KB |
Output is correct |
98 |
Correct |
369 ms |
35312 KB |
Output is correct |
99 |
Correct |
375 ms |
35324 KB |
Output is correct |
100 |
Correct |
394 ms |
35316 KB |
Output is correct |