#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int L = 21;
const int M = (1 << L) + 7;
const int K = 6;
int l, q;
int m;
char s[M];
int a[M];
int f[M];
int g[M];
int main() {
cin >> l >> q >> s;
m = (1 << l);
for (int i = 0; i < m; ++i) {
a[i] = s[i] - '0';
}
for (int i = 0; i < m; ++i) {
f[i] = a[i];
g[i] = a[i];
}
for (int j = 0; j < l; ++j) {
for (int i = 0; i < m; ++i) {
if ((i >> j) & 1) {
f[i] += f[i ^ (1 << j)];
g[i ^ (1 << j)] += g[i];
}
}
}
while (q--) {
/* int x;
scanf("%d", &x); */
static int t[3];
memset(t, 0, sizeof(t));
string tt;
cin >> tt;
for (int i = l - 1; i >= 0; --i) {
/* t[x % 3] |= (1 << i);
x /= 3; */
t[tt[i] == '?' ? 2 : tt[i] - '0'] |= (1 << (l - i - 1));
}
if (__builtin_popcount(t[1]) <= K) {
int ans = 0;
int ppc = __builtin_popcount(t[1]);
for (int z = t[1]; ; z = (z - 1) & t[1]) {
ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[2] | z];
if (z == 0) break;
}
printf("%d\n", ans);
} else if (__builtin_popcount(t[0]) <= K) {
int ans = 0;
int ppc = __builtin_popcount(t[0]);
for (int z = t[0]; ; z = (z - 1) & t[0]) {
ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * g[t[1] ^ t[0] ^ z];
if (z == 0) break;
}
printf("%d\n", ans);
} else {
assert(__builtin_popcount(t[2]) <= K);
int ans = 0;
for (int z = t[2]; ; z = (z - 1) & t[2]) {
ans += a[t[1] | z];
if (z == 0) break;
}
printf("%d\n", ans);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1741 ms |
15108 KB |
Output is correct |
12 |
Correct |
1616 ms |
14696 KB |
Output is correct |
13 |
Correct |
1636 ms |
13900 KB |
Output is correct |
14 |
Correct |
1611 ms |
14192 KB |
Output is correct |
15 |
Correct |
1614 ms |
15256 KB |
Output is correct |
16 |
Correct |
1645 ms |
14240 KB |
Output is correct |
17 |
Correct |
1656 ms |
14436 KB |
Output is correct |
18 |
Correct |
1580 ms |
16456 KB |
Output is correct |
19 |
Correct |
1770 ms |
13048 KB |
Output is correct |
20 |
Correct |
1742 ms |
14804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1741 ms |
15108 KB |
Output is correct |
12 |
Correct |
1616 ms |
14696 KB |
Output is correct |
13 |
Correct |
1636 ms |
13900 KB |
Output is correct |
14 |
Correct |
1611 ms |
14192 KB |
Output is correct |
15 |
Correct |
1614 ms |
15256 KB |
Output is correct |
16 |
Correct |
1645 ms |
14240 KB |
Output is correct |
17 |
Correct |
1656 ms |
14436 KB |
Output is correct |
18 |
Correct |
1580 ms |
16456 KB |
Output is correct |
19 |
Correct |
1770 ms |
13048 KB |
Output is correct |
20 |
Correct |
1742 ms |
14804 KB |
Output is correct |
21 |
Correct |
1929 ms |
18184 KB |
Output is correct |
22 |
Correct |
1680 ms |
18280 KB |
Output is correct |
23 |
Correct |
1753 ms |
17300 KB |
Output is correct |
24 |
Correct |
1743 ms |
17128 KB |
Output is correct |
25 |
Correct |
1748 ms |
19172 KB |
Output is correct |
26 |
Correct |
1824 ms |
17576 KB |
Output is correct |
27 |
Correct |
1824 ms |
17512 KB |
Output is correct |
28 |
Correct |
1741 ms |
20096 KB |
Output is correct |
29 |
Correct |
1957 ms |
16136 KB |
Output is correct |
30 |
Correct |
1821 ms |
18276 KB |
Output is correct |
31 |
Correct |
1814 ms |
18204 KB |
Output is correct |
32 |
Correct |
1772 ms |
18268 KB |
Output is correct |
33 |
Correct |
1749 ms |
16936 KB |
Output is correct |
34 |
Correct |
1756 ms |
17324 KB |
Output is correct |
35 |
Correct |
1772 ms |
17584 KB |
Output is correct |
36 |
Correct |
1621 ms |
16148 KB |
Output is correct |
37 |
Correct |
1625 ms |
18036 KB |
Output is correct |
38 |
Correct |
1839 ms |
16032 KB |
Output is correct |
39 |
Correct |
1905 ms |
17436 KB |
Output is correct |
40 |
Correct |
1797 ms |
17224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
147 ms |
15924 KB |
Output is correct |
12 |
Correct |
143 ms |
15944 KB |
Output is correct |
13 |
Correct |
151 ms |
15944 KB |
Output is correct |
14 |
Correct |
163 ms |
15808 KB |
Output is correct |
15 |
Correct |
152 ms |
15932 KB |
Output is correct |
16 |
Correct |
177 ms |
15824 KB |
Output is correct |
17 |
Correct |
162 ms |
15920 KB |
Output is correct |
18 |
Correct |
138 ms |
16072 KB |
Output is correct |
19 |
Correct |
142 ms |
15812 KB |
Output is correct |
20 |
Correct |
141 ms |
15992 KB |
Output is correct |
21 |
Correct |
153 ms |
15948 KB |
Output is correct |
22 |
Correct |
160 ms |
15924 KB |
Output is correct |
23 |
Correct |
145 ms |
15816 KB |
Output is correct |
24 |
Correct |
166 ms |
15800 KB |
Output is correct |
25 |
Correct |
166 ms |
15948 KB |
Output is correct |
26 |
Correct |
144 ms |
15704 KB |
Output is correct |
27 |
Correct |
147 ms |
15892 KB |
Output is correct |
28 |
Correct |
149 ms |
15736 KB |
Output is correct |
29 |
Correct |
155 ms |
15820 KB |
Output is correct |
30 |
Correct |
152 ms |
15808 KB |
Output is correct |
31 |
Correct |
145 ms |
15820 KB |
Output is correct |
32 |
Correct |
165 ms |
15856 KB |
Output is correct |
33 |
Correct |
170 ms |
15948 KB |
Output is correct |
34 |
Correct |
142 ms |
15800 KB |
Output is correct |
35 |
Correct |
162 ms |
15952 KB |
Output is correct |
36 |
Correct |
165 ms |
15908 KB |
Output is correct |
37 |
Correct |
166 ms |
15820 KB |
Output is correct |
38 |
Correct |
156 ms |
15844 KB |
Output is correct |
39 |
Correct |
162 ms |
15828 KB |
Output is correct |
40 |
Correct |
171 ms |
15820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1741 ms |
15108 KB |
Output is correct |
12 |
Correct |
1616 ms |
14696 KB |
Output is correct |
13 |
Correct |
1636 ms |
13900 KB |
Output is correct |
14 |
Correct |
1611 ms |
14192 KB |
Output is correct |
15 |
Correct |
1614 ms |
15256 KB |
Output is correct |
16 |
Correct |
1645 ms |
14240 KB |
Output is correct |
17 |
Correct |
1656 ms |
14436 KB |
Output is correct |
18 |
Correct |
1580 ms |
16456 KB |
Output is correct |
19 |
Correct |
1770 ms |
13048 KB |
Output is correct |
20 |
Correct |
1742 ms |
14804 KB |
Output is correct |
21 |
Correct |
1929 ms |
18184 KB |
Output is correct |
22 |
Correct |
1680 ms |
18280 KB |
Output is correct |
23 |
Correct |
1753 ms |
17300 KB |
Output is correct |
24 |
Correct |
1743 ms |
17128 KB |
Output is correct |
25 |
Correct |
1748 ms |
19172 KB |
Output is correct |
26 |
Correct |
1824 ms |
17576 KB |
Output is correct |
27 |
Correct |
1824 ms |
17512 KB |
Output is correct |
28 |
Correct |
1741 ms |
20096 KB |
Output is correct |
29 |
Correct |
1957 ms |
16136 KB |
Output is correct |
30 |
Correct |
1821 ms |
18276 KB |
Output is correct |
31 |
Correct |
1814 ms |
18204 KB |
Output is correct |
32 |
Correct |
1772 ms |
18268 KB |
Output is correct |
33 |
Correct |
1749 ms |
16936 KB |
Output is correct |
34 |
Correct |
1756 ms |
17324 KB |
Output is correct |
35 |
Correct |
1772 ms |
17584 KB |
Output is correct |
36 |
Correct |
1621 ms |
16148 KB |
Output is correct |
37 |
Correct |
1625 ms |
18036 KB |
Output is correct |
38 |
Correct |
1839 ms |
16032 KB |
Output is correct |
39 |
Correct |
1905 ms |
17436 KB |
Output is correct |
40 |
Correct |
1797 ms |
17224 KB |
Output is correct |
41 |
Correct |
147 ms |
15924 KB |
Output is correct |
42 |
Correct |
143 ms |
15944 KB |
Output is correct |
43 |
Correct |
151 ms |
15944 KB |
Output is correct |
44 |
Correct |
163 ms |
15808 KB |
Output is correct |
45 |
Correct |
152 ms |
15932 KB |
Output is correct |
46 |
Correct |
177 ms |
15824 KB |
Output is correct |
47 |
Correct |
162 ms |
15920 KB |
Output is correct |
48 |
Correct |
138 ms |
16072 KB |
Output is correct |
49 |
Correct |
142 ms |
15812 KB |
Output is correct |
50 |
Correct |
141 ms |
15992 KB |
Output is correct |
51 |
Correct |
153 ms |
15948 KB |
Output is correct |
52 |
Correct |
160 ms |
15924 KB |
Output is correct |
53 |
Correct |
145 ms |
15816 KB |
Output is correct |
54 |
Correct |
166 ms |
15800 KB |
Output is correct |
55 |
Correct |
166 ms |
15948 KB |
Output is correct |
56 |
Correct |
144 ms |
15704 KB |
Output is correct |
57 |
Correct |
147 ms |
15892 KB |
Output is correct |
58 |
Correct |
149 ms |
15736 KB |
Output is correct |
59 |
Correct |
155 ms |
15820 KB |
Output is correct |
60 |
Correct |
152 ms |
15808 KB |
Output is correct |
61 |
Correct |
145 ms |
15820 KB |
Output is correct |
62 |
Correct |
165 ms |
15856 KB |
Output is correct |
63 |
Correct |
170 ms |
15948 KB |
Output is correct |
64 |
Correct |
142 ms |
15800 KB |
Output is correct |
65 |
Correct |
162 ms |
15952 KB |
Output is correct |
66 |
Correct |
165 ms |
15908 KB |
Output is correct |
67 |
Correct |
166 ms |
15820 KB |
Output is correct |
68 |
Correct |
156 ms |
15844 KB |
Output is correct |
69 |
Correct |
162 ms |
15828 KB |
Output is correct |
70 |
Correct |
171 ms |
15820 KB |
Output is correct |
71 |
Execution timed out |
2009 ms |
40236 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |