#include<bits/stdc++.h>
using namespace std;
const int MAX_L = 20;
int L, q, sum[1 << MAX_L];
string s;
bool checkBit (int _a, int _bit) { return (_a >> _bit) & 1; }
int main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.INP", "r", stdin);
cin >> L >> q >> s;
for (int i = 0; i < (1 << L); ++i) sum[i] = s[i] - '0';
for (int i = 0; i < L; ++i) {
for (int j = 0; j < (1 << L); ++j) if (checkBit(j, i) ) sum[j] += sum[j ^ (1 << i)];
}
while (q --) {
string t; cin >> t; reverse(t.begin(), t.end() );
int maskQ = 0, maskO = 0;
for (int i = 0; i < L; ++i) {
if (t[i] == '?') maskQ |= (1 << i);
if (t[i] == '1') maskO |= (1 << i);
}
int ans = 0;
if (__builtin_popcount(maskQ) <= L / 2) {
for (int subMask = maskQ; ; subMask = (subMask - 1) & maskQ) {
ans += s[subMask | maskO] - '0';
if (!subMask) break ;
}
}
else {
for (int subMask = maskO; ; subMask = (subMask - 1) & maskO) {
if ( (__builtin_popcount(maskO) - __builtin_popcount(subMask & maskO) ) & 1) ans -= sum[maskQ | subMask];
else ans += sum[maskQ | subMask];
if (!subMask) break ;
}
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
291 ms |
15092 KB |
Output is correct |
12 |
Correct |
279 ms |
14712 KB |
Output is correct |
13 |
Correct |
243 ms |
13944 KB |
Output is correct |
14 |
Correct |
242 ms |
14104 KB |
Output is correct |
15 |
Correct |
271 ms |
15096 KB |
Output is correct |
16 |
Correct |
273 ms |
14244 KB |
Output is correct |
17 |
Correct |
268 ms |
14184 KB |
Output is correct |
18 |
Correct |
202 ms |
16120 KB |
Output is correct |
19 |
Correct |
203 ms |
13104 KB |
Output is correct |
20 |
Correct |
303 ms |
14712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
291 ms |
15092 KB |
Output is correct |
12 |
Correct |
279 ms |
14712 KB |
Output is correct |
13 |
Correct |
243 ms |
13944 KB |
Output is correct |
14 |
Correct |
242 ms |
14104 KB |
Output is correct |
15 |
Correct |
271 ms |
15096 KB |
Output is correct |
16 |
Correct |
273 ms |
14244 KB |
Output is correct |
17 |
Correct |
268 ms |
14184 KB |
Output is correct |
18 |
Correct |
202 ms |
16120 KB |
Output is correct |
19 |
Correct |
203 ms |
13104 KB |
Output is correct |
20 |
Correct |
303 ms |
14712 KB |
Output is correct |
21 |
Correct |
656 ms |
18028 KB |
Output is correct |
22 |
Correct |
355 ms |
18264 KB |
Output is correct |
23 |
Correct |
295 ms |
17276 KB |
Output is correct |
24 |
Correct |
280 ms |
17016 KB |
Output is correct |
25 |
Correct |
316 ms |
19116 KB |
Output is correct |
26 |
Correct |
322 ms |
17692 KB |
Output is correct |
27 |
Correct |
320 ms |
17576 KB |
Output is correct |
28 |
Correct |
216 ms |
20060 KB |
Output is correct |
29 |
Correct |
210 ms |
16104 KB |
Output is correct |
30 |
Correct |
434 ms |
18248 KB |
Output is correct |
31 |
Correct |
368 ms |
18040 KB |
Output is correct |
32 |
Correct |
322 ms |
18132 KB |
Output is correct |
33 |
Correct |
260 ms |
16996 KB |
Output is correct |
34 |
Correct |
283 ms |
17236 KB |
Output is correct |
35 |
Correct |
318 ms |
17572 KB |
Output is correct |
36 |
Correct |
204 ms |
16120 KB |
Output is correct |
37 |
Correct |
370 ms |
18164 KB |
Output is correct |
38 |
Correct |
204 ms |
16120 KB |
Output is correct |
39 |
Correct |
306 ms |
17376 KB |
Output is correct |
40 |
Correct |
278 ms |
17104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
140 ms |
7836 KB |
Output is correct |
12 |
Correct |
98 ms |
7952 KB |
Output is correct |
13 |
Correct |
60 ms |
7804 KB |
Output is correct |
14 |
Correct |
66 ms |
7836 KB |
Output is correct |
15 |
Correct |
61 ms |
8080 KB |
Output is correct |
16 |
Correct |
75 ms |
7884 KB |
Output is correct |
17 |
Correct |
73 ms |
7956 KB |
Output is correct |
18 |
Correct |
49 ms |
8092 KB |
Output is correct |
19 |
Correct |
49 ms |
7708 KB |
Output is correct |
20 |
Correct |
122 ms |
7960 KB |
Output is correct |
21 |
Correct |
141 ms |
7960 KB |
Output is correct |
22 |
Correct |
66 ms |
7848 KB |
Output is correct |
23 |
Correct |
53 ms |
7840 KB |
Output is correct |
24 |
Correct |
60 ms |
7804 KB |
Output is correct |
25 |
Correct |
71 ms |
7808 KB |
Output is correct |
26 |
Correct |
48 ms |
7704 KB |
Output is correct |
27 |
Correct |
138 ms |
7856 KB |
Output is correct |
28 |
Correct |
55 ms |
7832 KB |
Output is correct |
29 |
Correct |
63 ms |
7832 KB |
Output is correct |
30 |
Correct |
60 ms |
7808 KB |
Output is correct |
31 |
Correct |
54 ms |
7832 KB |
Output is correct |
32 |
Correct |
79 ms |
7960 KB |
Output is correct |
33 |
Correct |
71 ms |
7832 KB |
Output is correct |
34 |
Correct |
48 ms |
7832 KB |
Output is correct |
35 |
Correct |
74 ms |
7812 KB |
Output is correct |
36 |
Correct |
74 ms |
7832 KB |
Output is correct |
37 |
Correct |
75 ms |
7900 KB |
Output is correct |
38 |
Correct |
75 ms |
7960 KB |
Output is correct |
39 |
Correct |
76 ms |
7808 KB |
Output is correct |
40 |
Correct |
75 ms |
7836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
291 ms |
15092 KB |
Output is correct |
12 |
Correct |
279 ms |
14712 KB |
Output is correct |
13 |
Correct |
243 ms |
13944 KB |
Output is correct |
14 |
Correct |
242 ms |
14104 KB |
Output is correct |
15 |
Correct |
271 ms |
15096 KB |
Output is correct |
16 |
Correct |
273 ms |
14244 KB |
Output is correct |
17 |
Correct |
268 ms |
14184 KB |
Output is correct |
18 |
Correct |
202 ms |
16120 KB |
Output is correct |
19 |
Correct |
203 ms |
13104 KB |
Output is correct |
20 |
Correct |
303 ms |
14712 KB |
Output is correct |
21 |
Correct |
656 ms |
18028 KB |
Output is correct |
22 |
Correct |
355 ms |
18264 KB |
Output is correct |
23 |
Correct |
295 ms |
17276 KB |
Output is correct |
24 |
Correct |
280 ms |
17016 KB |
Output is correct |
25 |
Correct |
316 ms |
19116 KB |
Output is correct |
26 |
Correct |
322 ms |
17692 KB |
Output is correct |
27 |
Correct |
320 ms |
17576 KB |
Output is correct |
28 |
Correct |
216 ms |
20060 KB |
Output is correct |
29 |
Correct |
210 ms |
16104 KB |
Output is correct |
30 |
Correct |
434 ms |
18248 KB |
Output is correct |
31 |
Correct |
368 ms |
18040 KB |
Output is correct |
32 |
Correct |
322 ms |
18132 KB |
Output is correct |
33 |
Correct |
260 ms |
16996 KB |
Output is correct |
34 |
Correct |
283 ms |
17236 KB |
Output is correct |
35 |
Correct |
318 ms |
17572 KB |
Output is correct |
36 |
Correct |
204 ms |
16120 KB |
Output is correct |
37 |
Correct |
370 ms |
18164 KB |
Output is correct |
38 |
Correct |
204 ms |
16120 KB |
Output is correct |
39 |
Correct |
306 ms |
17376 KB |
Output is correct |
40 |
Correct |
278 ms |
17104 KB |
Output is correct |
41 |
Correct |
140 ms |
7836 KB |
Output is correct |
42 |
Correct |
98 ms |
7952 KB |
Output is correct |
43 |
Correct |
60 ms |
7804 KB |
Output is correct |
44 |
Correct |
66 ms |
7836 KB |
Output is correct |
45 |
Correct |
61 ms |
8080 KB |
Output is correct |
46 |
Correct |
75 ms |
7884 KB |
Output is correct |
47 |
Correct |
73 ms |
7956 KB |
Output is correct |
48 |
Correct |
49 ms |
8092 KB |
Output is correct |
49 |
Correct |
49 ms |
7708 KB |
Output is correct |
50 |
Correct |
122 ms |
7960 KB |
Output is correct |
51 |
Correct |
141 ms |
7960 KB |
Output is correct |
52 |
Correct |
66 ms |
7848 KB |
Output is correct |
53 |
Correct |
53 ms |
7840 KB |
Output is correct |
54 |
Correct |
60 ms |
7804 KB |
Output is correct |
55 |
Correct |
71 ms |
7808 KB |
Output is correct |
56 |
Correct |
48 ms |
7704 KB |
Output is correct |
57 |
Correct |
138 ms |
7856 KB |
Output is correct |
58 |
Correct |
55 ms |
7832 KB |
Output is correct |
59 |
Correct |
63 ms |
7832 KB |
Output is correct |
60 |
Correct |
60 ms |
7808 KB |
Output is correct |
61 |
Correct |
54 ms |
7832 KB |
Output is correct |
62 |
Correct |
79 ms |
7960 KB |
Output is correct |
63 |
Correct |
71 ms |
7832 KB |
Output is correct |
64 |
Correct |
48 ms |
7832 KB |
Output is correct |
65 |
Correct |
74 ms |
7812 KB |
Output is correct |
66 |
Correct |
74 ms |
7832 KB |
Output is correct |
67 |
Correct |
75 ms |
7900 KB |
Output is correct |
68 |
Correct |
75 ms |
7960 KB |
Output is correct |
69 |
Correct |
76 ms |
7808 KB |
Output is correct |
70 |
Correct |
75 ms |
7836 KB |
Output is correct |
71 |
Execution timed out |
2047 ms |
31552 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |