#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;
for (int i = 0; i < 1 << l; ++i) {
S[i] = A[i] = B[((1 << l) - 1) ^ i] = s[i] - '0';
}
for (int i = 0; i < l; ++i) {
for (int mask = 0; mask < 1 << l; ++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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4452 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
4 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4452 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
4 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
269 ms |
9276 KB |
Output is correct |
12 |
Correct |
204 ms |
9076 KB |
Output is correct |
13 |
Correct |
270 ms |
8252 KB |
Output is correct |
14 |
Correct |
213 ms |
8324 KB |
Output is correct |
15 |
Correct |
205 ms |
9304 KB |
Output is correct |
16 |
Correct |
242 ms |
8536 KB |
Output is correct |
17 |
Correct |
264 ms |
8436 KB |
Output is correct |
18 |
Correct |
161 ms |
10300 KB |
Output is correct |
19 |
Correct |
256 ms |
7348 KB |
Output is correct |
20 |
Correct |
259 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4452 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
4 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
269 ms |
9276 KB |
Output is correct |
12 |
Correct |
204 ms |
9076 KB |
Output is correct |
13 |
Correct |
270 ms |
8252 KB |
Output is correct |
14 |
Correct |
213 ms |
8324 KB |
Output is correct |
15 |
Correct |
205 ms |
9304 KB |
Output is correct |
16 |
Correct |
242 ms |
8536 KB |
Output is correct |
17 |
Correct |
264 ms |
8436 KB |
Output is correct |
18 |
Correct |
161 ms |
10300 KB |
Output is correct |
19 |
Correct |
256 ms |
7348 KB |
Output is correct |
20 |
Correct |
259 ms |
8908 KB |
Output is correct |
21 |
Correct |
320 ms |
9412 KB |
Output is correct |
22 |
Correct |
243 ms |
9540 KB |
Output is correct |
23 |
Correct |
284 ms |
8652 KB |
Output is correct |
24 |
Correct |
301 ms |
8396 KB |
Output is correct |
25 |
Correct |
238 ms |
10440 KB |
Output is correct |
26 |
Correct |
337 ms |
9072 KB |
Output is correct |
27 |
Correct |
299 ms |
8836 KB |
Output is correct |
28 |
Correct |
183 ms |
11352 KB |
Output is correct |
29 |
Correct |
347 ms |
7448 KB |
Output is correct |
30 |
Correct |
255 ms |
9572 KB |
Output is correct |
31 |
Correct |
258 ms |
9368 KB |
Output is correct |
32 |
Correct |
344 ms |
9356 KB |
Output is correct |
33 |
Correct |
239 ms |
8236 KB |
Output is correct |
34 |
Correct |
288 ms |
8512 KB |
Output is correct |
35 |
Correct |
364 ms |
8904 KB |
Output is correct |
36 |
Correct |
186 ms |
7476 KB |
Output is correct |
37 |
Correct |
224 ms |
9384 KB |
Output is correct |
38 |
Correct |
349 ms |
7436 KB |
Output is correct |
39 |
Correct |
346 ms |
8600 KB |
Output is correct |
40 |
Correct |
313 ms |
8412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4452 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
4 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
62 ms |
18988 KB |
Output is correct |
12 |
Correct |
59 ms |
19108 KB |
Output is correct |
13 |
Correct |
61 ms |
18916 KB |
Output is correct |
14 |
Correct |
56 ms |
18924 KB |
Output is correct |
15 |
Correct |
51 ms |
19028 KB |
Output is correct |
16 |
Correct |
65 ms |
18924 KB |
Output is correct |
17 |
Correct |
86 ms |
18972 KB |
Output is correct |
18 |
Correct |
52 ms |
19104 KB |
Output is correct |
19 |
Correct |
55 ms |
18792 KB |
Output is correct |
20 |
Correct |
53 ms |
19000 KB |
Output is correct |
21 |
Correct |
52 ms |
18916 KB |
Output is correct |
22 |
Correct |
65 ms |
18948 KB |
Output is correct |
23 |
Correct |
48 ms |
18836 KB |
Output is correct |
24 |
Correct |
73 ms |
18972 KB |
Output is correct |
25 |
Correct |
92 ms |
19032 KB |
Output is correct |
26 |
Correct |
43 ms |
18916 KB |
Output is correct |
27 |
Correct |
47 ms |
19016 KB |
Output is correct |
28 |
Correct |
54 ms |
18844 KB |
Output is correct |
29 |
Correct |
55 ms |
18900 KB |
Output is correct |
30 |
Correct |
72 ms |
18868 KB |
Output is correct |
31 |
Correct |
60 ms |
18900 KB |
Output is correct |
32 |
Correct |
60 ms |
18988 KB |
Output is correct |
33 |
Correct |
66 ms |
18916 KB |
Output is correct |
34 |
Correct |
48 ms |
18852 KB |
Output is correct |
35 |
Correct |
67 ms |
19176 KB |
Output is correct |
36 |
Correct |
72 ms |
19108 KB |
Output is correct |
37 |
Correct |
71 ms |
18936 KB |
Output is correct |
38 |
Correct |
62 ms |
19052 KB |
Output is correct |
39 |
Correct |
59 ms |
18956 KB |
Output is correct |
40 |
Correct |
57 ms |
18916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4452 KB |
Output is correct |
2 |
Correct |
3 ms |
4436 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
4 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
3 ms |
4436 KB |
Output is correct |
11 |
Correct |
269 ms |
9276 KB |
Output is correct |
12 |
Correct |
204 ms |
9076 KB |
Output is correct |
13 |
Correct |
270 ms |
8252 KB |
Output is correct |
14 |
Correct |
213 ms |
8324 KB |
Output is correct |
15 |
Correct |
205 ms |
9304 KB |
Output is correct |
16 |
Correct |
242 ms |
8536 KB |
Output is correct |
17 |
Correct |
264 ms |
8436 KB |
Output is correct |
18 |
Correct |
161 ms |
10300 KB |
Output is correct |
19 |
Correct |
256 ms |
7348 KB |
Output is correct |
20 |
Correct |
259 ms |
8908 KB |
Output is correct |
21 |
Correct |
320 ms |
9412 KB |
Output is correct |
22 |
Correct |
243 ms |
9540 KB |
Output is correct |
23 |
Correct |
284 ms |
8652 KB |
Output is correct |
24 |
Correct |
301 ms |
8396 KB |
Output is correct |
25 |
Correct |
238 ms |
10440 KB |
Output is correct |
26 |
Correct |
337 ms |
9072 KB |
Output is correct |
27 |
Correct |
299 ms |
8836 KB |
Output is correct |
28 |
Correct |
183 ms |
11352 KB |
Output is correct |
29 |
Correct |
347 ms |
7448 KB |
Output is correct |
30 |
Correct |
255 ms |
9572 KB |
Output is correct |
31 |
Correct |
258 ms |
9368 KB |
Output is correct |
32 |
Correct |
344 ms |
9356 KB |
Output is correct |
33 |
Correct |
239 ms |
8236 KB |
Output is correct |
34 |
Correct |
288 ms |
8512 KB |
Output is correct |
35 |
Correct |
364 ms |
8904 KB |
Output is correct |
36 |
Correct |
186 ms |
7476 KB |
Output is correct |
37 |
Correct |
224 ms |
9384 KB |
Output is correct |
38 |
Correct |
349 ms |
7436 KB |
Output is correct |
39 |
Correct |
346 ms |
8600 KB |
Output is correct |
40 |
Correct |
313 ms |
8412 KB |
Output is correct |
41 |
Correct |
62 ms |
18988 KB |
Output is correct |
42 |
Correct |
59 ms |
19108 KB |
Output is correct |
43 |
Correct |
61 ms |
18916 KB |
Output is correct |
44 |
Correct |
56 ms |
18924 KB |
Output is correct |
45 |
Correct |
51 ms |
19028 KB |
Output is correct |
46 |
Correct |
65 ms |
18924 KB |
Output is correct |
47 |
Correct |
86 ms |
18972 KB |
Output is correct |
48 |
Correct |
52 ms |
19104 KB |
Output is correct |
49 |
Correct |
55 ms |
18792 KB |
Output is correct |
50 |
Correct |
53 ms |
19000 KB |
Output is correct |
51 |
Correct |
52 ms |
18916 KB |
Output is correct |
52 |
Correct |
65 ms |
18948 KB |
Output is correct |
53 |
Correct |
48 ms |
18836 KB |
Output is correct |
54 |
Correct |
73 ms |
18972 KB |
Output is correct |
55 |
Correct |
92 ms |
19032 KB |
Output is correct |
56 |
Correct |
43 ms |
18916 KB |
Output is correct |
57 |
Correct |
47 ms |
19016 KB |
Output is correct |
58 |
Correct |
54 ms |
18844 KB |
Output is correct |
59 |
Correct |
55 ms |
18900 KB |
Output is correct |
60 |
Correct |
72 ms |
18868 KB |
Output is correct |
61 |
Correct |
60 ms |
18900 KB |
Output is correct |
62 |
Correct |
60 ms |
18988 KB |
Output is correct |
63 |
Correct |
66 ms |
18916 KB |
Output is correct |
64 |
Correct |
48 ms |
18852 KB |
Output is correct |
65 |
Correct |
67 ms |
19176 KB |
Output is correct |
66 |
Correct |
72 ms |
19108 KB |
Output is correct |
67 |
Correct |
71 ms |
18936 KB |
Output is correct |
68 |
Correct |
62 ms |
19052 KB |
Output is correct |
69 |
Correct |
59 ms |
18956 KB |
Output is correct |
70 |
Correct |
57 ms |
18916 KB |
Output is correct |
71 |
Correct |
363 ms |
23832 KB |
Output is correct |
72 |
Correct |
360 ms |
23940 KB |
Output is correct |
73 |
Correct |
593 ms |
22428 KB |
Output is correct |
74 |
Correct |
634 ms |
22756 KB |
Output is correct |
75 |
Correct |
349 ms |
24688 KB |
Output is correct |
76 |
Correct |
836 ms |
23080 KB |
Output is correct |
77 |
Correct |
796 ms |
22984 KB |
Output is correct |
78 |
Correct |
244 ms |
26720 KB |
Output is correct |
79 |
Correct |
393 ms |
20744 KB |
Output is correct |
80 |
Correct |
442 ms |
23864 KB |
Output is correct |
81 |
Correct |
522 ms |
23624 KB |
Output is correct |
82 |
Correct |
606 ms |
22620 KB |
Output is correct |
83 |
Correct |
368 ms |
21844 KB |
Output is correct |
84 |
Correct |
781 ms |
22452 KB |
Output is correct |
85 |
Correct |
716 ms |
22716 KB |
Output is correct |
86 |
Correct |
237 ms |
20436 KB |
Output is correct |
87 |
Correct |
326 ms |
23408 KB |
Output is correct |
88 |
Correct |
439 ms |
20408 KB |
Output is correct |
89 |
Correct |
578 ms |
22016 KB |
Output is correct |
90 |
Correct |
492 ms |
22248 KB |
Output is correct |
91 |
Correct |
407 ms |
21496 KB |
Output is correct |
92 |
Correct |
675 ms |
22516 KB |
Output is correct |
93 |
Correct |
715 ms |
22244 KB |
Output is correct |
94 |
Correct |
287 ms |
20020 KB |
Output is correct |
95 |
Correct |
607 ms |
22240 KB |
Output is correct |
96 |
Correct |
620 ms |
22116 KB |
Output is correct |
97 |
Correct |
653 ms |
22052 KB |
Output is correct |
98 |
Correct |
669 ms |
22124 KB |
Output is correct |
99 |
Correct |
668 ms |
21972 KB |
Output is correct |
100 |
Correct |
599 ms |
21876 KB |
Output is correct |