#include <bits/stdc++.h>
#define MASK(x) (1LL<<(x))
#define endl '\n'
using namespace std;
const int MX = MASK(20) + 5;
int n, q;
string a;
int f1[MX];
int f2[MX];
void nhap(){
cin >> n >> q;
cin >> a;
}
void solve(){
for(int i=0; i<MASK(n); i++){
f1[i] = f2[i] = a[i] - '0';
}
for(int i=0; i<n; i++){
for(int mask=0; mask<MASK(n); mask++){
if(mask&MASK(i)) f2[mask] += f2[mask^MASK(i)];
else f1[mask] += f1[mask^MASK(i)];
}
}
while(q--){
string s; cin >> s;
int m0 = 0;
int m1 = 0;
int m2 = 0;
for(char c: s){
m0 = (m0 << 1) | (c == '0'? 1 : 0);
m1 = (m1 << 1) | (c == '1'? 1 : 0);
m2 = (m2 << 1) | (c == '?'? 1 : 0);
}
#define cntbit(x) __builtin_popcount(x)
int ans = 0;
if(cntbit(m0) < 7){
for(int mask=m0; ; mask=(mask - 1)&m0){
ans += cntbit(mask)&1? -f1[m1|mask] : f1[m1|mask];
if(mask == 0) break;
}
}
else if(cntbit(m1) < 7){
for(int mask=m1; ; mask=(mask - 1)&m1){
ans += (cntbit(m1) - cntbit(mask))&1? -f2[m2|mask] : f2[m2|mask];
if(mask == 0) break;
}
}
else if(cntbit(m2) < 7){
for(int mask=m2; ; mask=(mask - 1)&m2){
ans += a[mask|m1] - '0';
if(mask == 0) break;
}
}
cout << ans << endl;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
nhap();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
132 ms |
17144 KB |
Output is correct |
12 |
Correct |
208 ms |
16852 KB |
Output is correct |
13 |
Correct |
242 ms |
16120 KB |
Output is correct |
14 |
Correct |
218 ms |
16068 KB |
Output is correct |
15 |
Correct |
158 ms |
17236 KB |
Output is correct |
16 |
Correct |
174 ms |
16208 KB |
Output is correct |
17 |
Correct |
211 ms |
16288 KB |
Output is correct |
18 |
Correct |
110 ms |
18240 KB |
Output is correct |
19 |
Correct |
210 ms |
15248 KB |
Output is correct |
20 |
Correct |
141 ms |
16924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
132 ms |
17144 KB |
Output is correct |
12 |
Correct |
208 ms |
16852 KB |
Output is correct |
13 |
Correct |
242 ms |
16120 KB |
Output is correct |
14 |
Correct |
218 ms |
16068 KB |
Output is correct |
15 |
Correct |
158 ms |
17236 KB |
Output is correct |
16 |
Correct |
174 ms |
16208 KB |
Output is correct |
17 |
Correct |
211 ms |
16288 KB |
Output is correct |
18 |
Correct |
110 ms |
18240 KB |
Output is correct |
19 |
Correct |
210 ms |
15248 KB |
Output is correct |
20 |
Correct |
141 ms |
16924 KB |
Output is correct |
21 |
Correct |
153 ms |
20084 KB |
Output is correct |
22 |
Correct |
229 ms |
20384 KB |
Output is correct |
23 |
Correct |
345 ms |
19224 KB |
Output is correct |
24 |
Correct |
257 ms |
19024 KB |
Output is correct |
25 |
Correct |
186 ms |
21072 KB |
Output is correct |
26 |
Correct |
224 ms |
19908 KB |
Output is correct |
27 |
Correct |
247 ms |
19540 KB |
Output is correct |
28 |
Correct |
117 ms |
22100 KB |
Output is correct |
29 |
Correct |
309 ms |
18288 KB |
Output is correct |
30 |
Correct |
178 ms |
20308 KB |
Output is correct |
31 |
Correct |
213 ms |
20028 KB |
Output is correct |
32 |
Correct |
217 ms |
20052 KB |
Output is correct |
33 |
Correct |
174 ms |
19028 KB |
Output is correct |
34 |
Correct |
241 ms |
19004 KB |
Output is correct |
35 |
Correct |
253 ms |
19508 KB |
Output is correct |
36 |
Correct |
107 ms |
18000 KB |
Output is correct |
37 |
Correct |
153 ms |
20248 KB |
Output is correct |
38 |
Correct |
267 ms |
18024 KB |
Output is correct |
39 |
Correct |
231 ms |
19192 KB |
Output is correct |
40 |
Correct |
211 ms |
19028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
29 ms |
12028 KB |
Output is correct |
12 |
Correct |
37 ms |
12108 KB |
Output is correct |
13 |
Correct |
37 ms |
12016 KB |
Output is correct |
14 |
Correct |
44 ms |
11840 KB |
Output is correct |
15 |
Correct |
31 ms |
12024 KB |
Output is correct |
16 |
Correct |
43 ms |
12016 KB |
Output is correct |
17 |
Correct |
38 ms |
12016 KB |
Output is correct |
18 |
Correct |
26 ms |
12208 KB |
Output is correct |
19 |
Correct |
30 ms |
11772 KB |
Output is correct |
20 |
Correct |
30 ms |
12020 KB |
Output is correct |
21 |
Correct |
36 ms |
12016 KB |
Output is correct |
22 |
Correct |
42 ms |
12020 KB |
Output is correct |
23 |
Correct |
31 ms |
11844 KB |
Output is correct |
24 |
Correct |
40 ms |
12024 KB |
Output is correct |
25 |
Correct |
38 ms |
12032 KB |
Output is correct |
26 |
Correct |
25 ms |
11860 KB |
Output is correct |
27 |
Correct |
30 ms |
12024 KB |
Output is correct |
28 |
Correct |
30 ms |
11760 KB |
Output is correct |
29 |
Correct |
35 ms |
12024 KB |
Output is correct |
30 |
Correct |
36 ms |
11848 KB |
Output is correct |
31 |
Correct |
34 ms |
12020 KB |
Output is correct |
32 |
Correct |
43 ms |
12016 KB |
Output is correct |
33 |
Correct |
43 ms |
12012 KB |
Output is correct |
34 |
Correct |
25 ms |
11768 KB |
Output is correct |
35 |
Correct |
37 ms |
12032 KB |
Output is correct |
36 |
Correct |
37 ms |
12020 KB |
Output is correct |
37 |
Correct |
35 ms |
12020 KB |
Output is correct |
38 |
Correct |
36 ms |
12020 KB |
Output is correct |
39 |
Correct |
36 ms |
12016 KB |
Output is correct |
40 |
Correct |
36 ms |
12020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
132 ms |
17144 KB |
Output is correct |
12 |
Correct |
208 ms |
16852 KB |
Output is correct |
13 |
Correct |
242 ms |
16120 KB |
Output is correct |
14 |
Correct |
218 ms |
16068 KB |
Output is correct |
15 |
Correct |
158 ms |
17236 KB |
Output is correct |
16 |
Correct |
174 ms |
16208 KB |
Output is correct |
17 |
Correct |
211 ms |
16288 KB |
Output is correct |
18 |
Correct |
110 ms |
18240 KB |
Output is correct |
19 |
Correct |
210 ms |
15248 KB |
Output is correct |
20 |
Correct |
141 ms |
16924 KB |
Output is correct |
21 |
Correct |
153 ms |
20084 KB |
Output is correct |
22 |
Correct |
229 ms |
20384 KB |
Output is correct |
23 |
Correct |
345 ms |
19224 KB |
Output is correct |
24 |
Correct |
257 ms |
19024 KB |
Output is correct |
25 |
Correct |
186 ms |
21072 KB |
Output is correct |
26 |
Correct |
224 ms |
19908 KB |
Output is correct |
27 |
Correct |
247 ms |
19540 KB |
Output is correct |
28 |
Correct |
117 ms |
22100 KB |
Output is correct |
29 |
Correct |
309 ms |
18288 KB |
Output is correct |
30 |
Correct |
178 ms |
20308 KB |
Output is correct |
31 |
Correct |
213 ms |
20028 KB |
Output is correct |
32 |
Correct |
217 ms |
20052 KB |
Output is correct |
33 |
Correct |
174 ms |
19028 KB |
Output is correct |
34 |
Correct |
241 ms |
19004 KB |
Output is correct |
35 |
Correct |
253 ms |
19508 KB |
Output is correct |
36 |
Correct |
107 ms |
18000 KB |
Output is correct |
37 |
Correct |
153 ms |
20248 KB |
Output is correct |
38 |
Correct |
267 ms |
18024 KB |
Output is correct |
39 |
Correct |
231 ms |
19192 KB |
Output is correct |
40 |
Correct |
211 ms |
19028 KB |
Output is correct |
41 |
Correct |
29 ms |
12028 KB |
Output is correct |
42 |
Correct |
37 ms |
12108 KB |
Output is correct |
43 |
Correct |
37 ms |
12016 KB |
Output is correct |
44 |
Correct |
44 ms |
11840 KB |
Output is correct |
45 |
Correct |
31 ms |
12024 KB |
Output is correct |
46 |
Correct |
43 ms |
12016 KB |
Output is correct |
47 |
Correct |
38 ms |
12016 KB |
Output is correct |
48 |
Correct |
26 ms |
12208 KB |
Output is correct |
49 |
Correct |
30 ms |
11772 KB |
Output is correct |
50 |
Correct |
30 ms |
12020 KB |
Output is correct |
51 |
Correct |
36 ms |
12016 KB |
Output is correct |
52 |
Correct |
42 ms |
12020 KB |
Output is correct |
53 |
Correct |
31 ms |
11844 KB |
Output is correct |
54 |
Correct |
40 ms |
12024 KB |
Output is correct |
55 |
Correct |
38 ms |
12032 KB |
Output is correct |
56 |
Correct |
25 ms |
11860 KB |
Output is correct |
57 |
Correct |
30 ms |
12024 KB |
Output is correct |
58 |
Correct |
30 ms |
11760 KB |
Output is correct |
59 |
Correct |
35 ms |
12024 KB |
Output is correct |
60 |
Correct |
36 ms |
11848 KB |
Output is correct |
61 |
Correct |
34 ms |
12020 KB |
Output is correct |
62 |
Correct |
43 ms |
12016 KB |
Output is correct |
63 |
Correct |
43 ms |
12012 KB |
Output is correct |
64 |
Correct |
25 ms |
11768 KB |
Output is correct |
65 |
Correct |
37 ms |
12032 KB |
Output is correct |
66 |
Correct |
37 ms |
12020 KB |
Output is correct |
67 |
Correct |
35 ms |
12020 KB |
Output is correct |
68 |
Correct |
36 ms |
12020 KB |
Output is correct |
69 |
Correct |
36 ms |
12016 KB |
Output is correct |
70 |
Correct |
36 ms |
12020 KB |
Output is correct |
71 |
Correct |
241 ms |
36332 KB |
Output is correct |
72 |
Correct |
263 ms |
36340 KB |
Output is correct |
73 |
Correct |
389 ms |
35132 KB |
Output is correct |
74 |
Correct |
521 ms |
35188 KB |
Output is correct |
75 |
Correct |
288 ms |
37312 KB |
Output is correct |
76 |
Correct |
507 ms |
35840 KB |
Output is correct |
77 |
Correct |
413 ms |
35412 KB |
Output is correct |
78 |
Correct |
184 ms |
39576 KB |
Output is correct |
79 |
Correct |
230 ms |
33268 KB |
Output is correct |
80 |
Correct |
258 ms |
36604 KB |
Output is correct |
81 |
Correct |
381 ms |
36340 KB |
Output is correct |
82 |
Correct |
481 ms |
35228 KB |
Output is correct |
83 |
Correct |
286 ms |
34288 KB |
Output is correct |
84 |
Correct |
455 ms |
35312 KB |
Output is correct |
85 |
Correct |
459 ms |
35524 KB |
Output is correct |
86 |
Correct |
147 ms |
33268 KB |
Output is correct |
87 |
Correct |
243 ms |
36152 KB |
Output is correct |
88 |
Correct |
255 ms |
33264 KB |
Output is correct |
89 |
Correct |
330 ms |
34892 KB |
Output is correct |
90 |
Correct |
363 ms |
35132 KB |
Output is correct |
91 |
Correct |
304 ms |
34532 KB |
Output is correct |
92 |
Correct |
515 ms |
35572 KB |
Output is correct |
93 |
Correct |
451 ms |
35376 KB |
Output is correct |
94 |
Correct |
152 ms |
33212 KB |
Output is correct |
95 |
Correct |
368 ms |
35408 KB |
Output is correct |
96 |
Correct |
372 ms |
35312 KB |
Output is correct |
97 |
Correct |
343 ms |
35316 KB |
Output is correct |
98 |
Correct |
357 ms |
35316 KB |
Output is correct |
99 |
Correct |
353 ms |
35404 KB |
Output is correct |
100 |
Correct |
364 ms |
35316 KB |
Output is correct |