#include <bits/stdc++.h>
using namespace std;
const int L = 20;
int S[1 << L], A[1 << L], B[1 << L], popcnt[1 << L];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 1; i < 1 << L; ++i) {
popcnt[i] = popcnt[i - (i & -i)] + 1;
}
int l, q;
string s;
cin >> l >> q >> s;
int n = 1 << l;
for (int i = 0; i < n; ++i) {
S[i] = A[i] = B[(n - 1) ^ i] = s[i] - '0';
}
for (int i = 0; i < l; ++i) {
for (int mask = 0; mask < n; ++mask) {
if (mask & 1 << i) {
A[mask] += A[mask ^ 1 << i];
B[mask] += B[mask ^ 1 << i];
}
}
}
while (q--) {
string t;
cin >> t;
reverse(t.begin(), t.end());
int mask0 = 0, mask1 = 0, mask2 = 0;
for (int i = 0; i < l; ++i) {
if (t[i] == '0') {
mask0 ^= 1 << i;
} else if (t[i] == '1') {
mask1 ^= 1 << i;
} else {
mask2 ^= 1 << i;
}
}
int ans = 0;
if (popcnt[mask1] <= 6) {
for (int mask = mask1; mask; mask = (mask - 1) & mask1) {
ans += A[mask ^ mask2] * (popcnt[mask ^ mask1] & 1 ? -1 : 1);
}
ans += A[mask2] * (popcnt[mask1] & 1 ? -1 : 1);
} else if (popcnt[mask0] <= 6) {
for (int mask = mask0; mask; mask = (mask - 1) & mask0) {
ans += B[mask ^ mask2] * (popcnt[mask ^ mask0] & 1 ? -1 : 1);
}
ans += B[mask2] * (popcnt[mask0] & 1 ? -1 : 1);
} else {
for (int mask = mask2; mask; mask = (mask - 1) & mask2) {
ans += S[mask ^ mask1];
}
ans += S[mask1];
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
4 ms |
4436 KB |
Output is correct |
5 |
Correct |
4 ms |
4436 KB |
Output is correct |
6 |
Correct |
5 ms |
4460 KB |
Output is correct |
7 |
Correct |
5 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4388 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
4 ms |
4436 KB |
Output is correct |
5 |
Correct |
4 ms |
4436 KB |
Output is correct |
6 |
Correct |
5 ms |
4460 KB |
Output is correct |
7 |
Correct |
5 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4388 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
248 ms |
8448 KB |
Output is correct |
12 |
Correct |
185 ms |
8128 KB |
Output is correct |
13 |
Correct |
237 ms |
7444 KB |
Output is correct |
14 |
Correct |
212 ms |
7452 KB |
Output is correct |
15 |
Correct |
201 ms |
8424 KB |
Output is correct |
16 |
Correct |
285 ms |
7636 KB |
Output is correct |
17 |
Correct |
247 ms |
7600 KB |
Output is correct |
18 |
Correct |
170 ms |
9400 KB |
Output is correct |
19 |
Correct |
229 ms |
6488 KB |
Output is correct |
20 |
Correct |
238 ms |
8076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
4 ms |
4436 KB |
Output is correct |
5 |
Correct |
4 ms |
4436 KB |
Output is correct |
6 |
Correct |
5 ms |
4460 KB |
Output is correct |
7 |
Correct |
5 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4388 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
248 ms |
8448 KB |
Output is correct |
12 |
Correct |
185 ms |
8128 KB |
Output is correct |
13 |
Correct |
237 ms |
7444 KB |
Output is correct |
14 |
Correct |
212 ms |
7452 KB |
Output is correct |
15 |
Correct |
201 ms |
8424 KB |
Output is correct |
16 |
Correct |
285 ms |
7636 KB |
Output is correct |
17 |
Correct |
247 ms |
7600 KB |
Output is correct |
18 |
Correct |
170 ms |
9400 KB |
Output is correct |
19 |
Correct |
229 ms |
6488 KB |
Output is correct |
20 |
Correct |
238 ms |
8076 KB |
Output is correct |
21 |
Correct |
316 ms |
8664 KB |
Output is correct |
22 |
Correct |
261 ms |
8632 KB |
Output is correct |
23 |
Correct |
303 ms |
7676 KB |
Output is correct |
24 |
Correct |
261 ms |
7572 KB |
Output is correct |
25 |
Correct |
227 ms |
9528 KB |
Output is correct |
26 |
Correct |
331 ms |
7976 KB |
Output is correct |
27 |
Correct |
295 ms |
8012 KB |
Output is correct |
28 |
Correct |
199 ms |
10520 KB |
Output is correct |
29 |
Correct |
310 ms |
6488 KB |
Output is correct |
30 |
Correct |
267 ms |
8652 KB |
Output is correct |
31 |
Correct |
267 ms |
8496 KB |
Output is correct |
32 |
Correct |
274 ms |
8548 KB |
Output is correct |
33 |
Correct |
233 ms |
7448 KB |
Output is correct |
34 |
Correct |
305 ms |
7464 KB |
Output is correct |
35 |
Correct |
337 ms |
8064 KB |
Output is correct |
36 |
Correct |
181 ms |
6616 KB |
Output is correct |
37 |
Correct |
238 ms |
8736 KB |
Output is correct |
38 |
Correct |
304 ms |
6668 KB |
Output is correct |
39 |
Correct |
373 ms |
7852 KB |
Output is correct |
40 |
Correct |
306 ms |
7664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
4 ms |
4436 KB |
Output is correct |
5 |
Correct |
4 ms |
4436 KB |
Output is correct |
6 |
Correct |
5 ms |
4460 KB |
Output is correct |
7 |
Correct |
5 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4388 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
69 ms |
18224 KB |
Output is correct |
12 |
Correct |
61 ms |
18244 KB |
Output is correct |
13 |
Correct |
73 ms |
18164 KB |
Output is correct |
14 |
Correct |
70 ms |
18152 KB |
Output is correct |
15 |
Correct |
51 ms |
18196 KB |
Output is correct |
16 |
Correct |
67 ms |
18168 KB |
Output is correct |
17 |
Correct |
67 ms |
18148 KB |
Output is correct |
18 |
Correct |
50 ms |
18392 KB |
Output is correct |
19 |
Correct |
60 ms |
18012 KB |
Output is correct |
20 |
Correct |
60 ms |
18160 KB |
Output is correct |
21 |
Correct |
57 ms |
18184 KB |
Output is correct |
22 |
Correct |
69 ms |
18160 KB |
Output is correct |
23 |
Correct |
70 ms |
18152 KB |
Output is correct |
24 |
Correct |
91 ms |
18140 KB |
Output is correct |
25 |
Correct |
69 ms |
18208 KB |
Output is correct |
26 |
Correct |
58 ms |
18028 KB |
Output is correct |
27 |
Correct |
50 ms |
18136 KB |
Output is correct |
28 |
Correct |
61 ms |
18032 KB |
Output is correct |
29 |
Correct |
64 ms |
18136 KB |
Output is correct |
30 |
Correct |
74 ms |
18128 KB |
Output is correct |
31 |
Correct |
58 ms |
18140 KB |
Output is correct |
32 |
Correct |
68 ms |
18204 KB |
Output is correct |
33 |
Correct |
66 ms |
18144 KB |
Output is correct |
34 |
Correct |
48 ms |
18012 KB |
Output is correct |
35 |
Correct |
58 ms |
18152 KB |
Output is correct |
36 |
Correct |
86 ms |
18136 KB |
Output is correct |
37 |
Correct |
91 ms |
18160 KB |
Output is correct |
38 |
Correct |
63 ms |
18112 KB |
Output is correct |
39 |
Correct |
64 ms |
18188 KB |
Output is correct |
40 |
Correct |
60 ms |
18188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4436 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
4 ms |
4436 KB |
Output is correct |
5 |
Correct |
4 ms |
4436 KB |
Output is correct |
6 |
Correct |
5 ms |
4460 KB |
Output is correct |
7 |
Correct |
5 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4388 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
248 ms |
8448 KB |
Output is correct |
12 |
Correct |
185 ms |
8128 KB |
Output is correct |
13 |
Correct |
237 ms |
7444 KB |
Output is correct |
14 |
Correct |
212 ms |
7452 KB |
Output is correct |
15 |
Correct |
201 ms |
8424 KB |
Output is correct |
16 |
Correct |
285 ms |
7636 KB |
Output is correct |
17 |
Correct |
247 ms |
7600 KB |
Output is correct |
18 |
Correct |
170 ms |
9400 KB |
Output is correct |
19 |
Correct |
229 ms |
6488 KB |
Output is correct |
20 |
Correct |
238 ms |
8076 KB |
Output is correct |
21 |
Correct |
316 ms |
8664 KB |
Output is correct |
22 |
Correct |
261 ms |
8632 KB |
Output is correct |
23 |
Correct |
303 ms |
7676 KB |
Output is correct |
24 |
Correct |
261 ms |
7572 KB |
Output is correct |
25 |
Correct |
227 ms |
9528 KB |
Output is correct |
26 |
Correct |
331 ms |
7976 KB |
Output is correct |
27 |
Correct |
295 ms |
8012 KB |
Output is correct |
28 |
Correct |
199 ms |
10520 KB |
Output is correct |
29 |
Correct |
310 ms |
6488 KB |
Output is correct |
30 |
Correct |
267 ms |
8652 KB |
Output is correct |
31 |
Correct |
267 ms |
8496 KB |
Output is correct |
32 |
Correct |
274 ms |
8548 KB |
Output is correct |
33 |
Correct |
233 ms |
7448 KB |
Output is correct |
34 |
Correct |
305 ms |
7464 KB |
Output is correct |
35 |
Correct |
337 ms |
8064 KB |
Output is correct |
36 |
Correct |
181 ms |
6616 KB |
Output is correct |
37 |
Correct |
238 ms |
8736 KB |
Output is correct |
38 |
Correct |
304 ms |
6668 KB |
Output is correct |
39 |
Correct |
373 ms |
7852 KB |
Output is correct |
40 |
Correct |
306 ms |
7664 KB |
Output is correct |
41 |
Correct |
69 ms |
18224 KB |
Output is correct |
42 |
Correct |
61 ms |
18244 KB |
Output is correct |
43 |
Correct |
73 ms |
18164 KB |
Output is correct |
44 |
Correct |
70 ms |
18152 KB |
Output is correct |
45 |
Correct |
51 ms |
18196 KB |
Output is correct |
46 |
Correct |
67 ms |
18168 KB |
Output is correct |
47 |
Correct |
67 ms |
18148 KB |
Output is correct |
48 |
Correct |
50 ms |
18392 KB |
Output is correct |
49 |
Correct |
60 ms |
18012 KB |
Output is correct |
50 |
Correct |
60 ms |
18160 KB |
Output is correct |
51 |
Correct |
57 ms |
18184 KB |
Output is correct |
52 |
Correct |
69 ms |
18160 KB |
Output is correct |
53 |
Correct |
70 ms |
18152 KB |
Output is correct |
54 |
Correct |
91 ms |
18140 KB |
Output is correct |
55 |
Correct |
69 ms |
18208 KB |
Output is correct |
56 |
Correct |
58 ms |
18028 KB |
Output is correct |
57 |
Correct |
50 ms |
18136 KB |
Output is correct |
58 |
Correct |
61 ms |
18032 KB |
Output is correct |
59 |
Correct |
64 ms |
18136 KB |
Output is correct |
60 |
Correct |
74 ms |
18128 KB |
Output is correct |
61 |
Correct |
58 ms |
18140 KB |
Output is correct |
62 |
Correct |
68 ms |
18204 KB |
Output is correct |
63 |
Correct |
66 ms |
18144 KB |
Output is correct |
64 |
Correct |
48 ms |
18012 KB |
Output is correct |
65 |
Correct |
58 ms |
18152 KB |
Output is correct |
66 |
Correct |
86 ms |
18136 KB |
Output is correct |
67 |
Correct |
91 ms |
18160 KB |
Output is correct |
68 |
Correct |
63 ms |
18112 KB |
Output is correct |
69 |
Correct |
64 ms |
18188 KB |
Output is correct |
70 |
Correct |
60 ms |
18188 KB |
Output is correct |
71 |
Correct |
435 ms |
23000 KB |
Output is correct |
72 |
Correct |
412 ms |
23004 KB |
Output is correct |
73 |
Correct |
579 ms |
21524 KB |
Output is correct |
74 |
Correct |
783 ms |
21932 KB |
Output is correct |
75 |
Correct |
419 ms |
23980 KB |
Output is correct |
76 |
Correct |
999 ms |
22204 KB |
Output is correct |
77 |
Correct |
723 ms |
22076 KB |
Output is correct |
78 |
Correct |
315 ms |
26056 KB |
Output is correct |
79 |
Correct |
410 ms |
19812 KB |
Output is correct |
80 |
Correct |
541 ms |
23032 KB |
Output is correct |
81 |
Correct |
483 ms |
22868 KB |
Output is correct |
82 |
Correct |
646 ms |
21924 KB |
Output is correct |
83 |
Correct |
496 ms |
21136 KB |
Output is correct |
84 |
Correct |
820 ms |
21896 KB |
Output is correct |
85 |
Correct |
879 ms |
22148 KB |
Output is correct |
86 |
Correct |
309 ms |
19956 KB |
Output is correct |
87 |
Correct |
392 ms |
22928 KB |
Output is correct |
88 |
Correct |
595 ms |
19884 KB |
Output is correct |
89 |
Correct |
701 ms |
21636 KB |
Output is correct |
90 |
Correct |
623 ms |
21932 KB |
Output is correct |
91 |
Correct |
500 ms |
21072 KB |
Output is correct |
92 |
Correct |
750 ms |
22232 KB |
Output is correct |
93 |
Correct |
854 ms |
22064 KB |
Output is correct |
94 |
Correct |
255 ms |
20024 KB |
Output is correct |
95 |
Correct |
734 ms |
21964 KB |
Output is correct |
96 |
Correct |
738 ms |
22052 KB |
Output is correct |
97 |
Correct |
724 ms |
21928 KB |
Output is correct |
98 |
Correct |
643 ms |
22040 KB |
Output is correct |
99 |
Correct |
643 ms |
22160 KB |
Output is correct |
100 |
Correct |
676 ms |
21980 KB |
Output is correct |