#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("popcnt")
const int B = 20;
int dp[1 << B], dq[1 << B], arr[1 << B];
int n, q;
int main () {
cin >> n >> q;
for (int i = 0; i < (1 << n); i++) {
char s; cin >> s; int x = s - '0';
arr[i] = dp[i] = dq[i] = x;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << n); j++) {
if (!(j & (1 << i))) dq[j] += dq[j ^ (1 << i)];
}
for (int j = (1 << n) - 1; j >= 0; j--) {
if (j & (1 << i)) dp[j] += dp[j ^ (1 << i)];
}
}
while (q--) {
string s; cin >> s;
int a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
a ^= 1 << (n - i - 1);
} else if (s[i] == '1') {
b ^= 1 << (n - i - 1);
} else {
c ^= 1 << (n - i - 1);
}
}
int ret = 0;
if (__builtin_popcount(a) <= 6) {
int m = a;
while (true) {
if (__builtin_popcount(m) & 1) {
ret -= dq[b | m];
} else {
ret += dq[b | m];
}
if (m == 0) break;
m = (m - 1) & a;
}
} else if (__builtin_popcount(b) <= 6) {
int m = b;
while (true) {
if (__builtin_popcount(m) & 1) {
ret -= dp[c | m];
} else {
ret += dp[c | m];
}
if (m == 0) break;
m = (m - 1) & b;
}
} else {
int m = c;
while (true) {
ret += arr[b ^ m];
if (m == 0) break;
m = (m - 1) & c;
}
}
cout << (ret < 0 ? -ret : ret) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
3 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
3 ms |
4444 KB |
Output is correct |
11 |
Correct |
1478 ms |
8608 KB |
Output is correct |
12 |
Correct |
1507 ms |
8144 KB |
Output is correct |
13 |
Correct |
1507 ms |
7348 KB |
Output is correct |
14 |
Correct |
1504 ms |
7736 KB |
Output is correct |
15 |
Correct |
1465 ms |
8516 KB |
Output is correct |
16 |
Correct |
1538 ms |
7540 KB |
Output is correct |
17 |
Correct |
1530 ms |
7436 KB |
Output is correct |
18 |
Correct |
1443 ms |
9360 KB |
Output is correct |
19 |
Correct |
1515 ms |
6680 KB |
Output is correct |
20 |
Correct |
1489 ms |
8112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
3 ms |
4444 KB |
Output is correct |
11 |
Correct |
1478 ms |
8608 KB |
Output is correct |
12 |
Correct |
1507 ms |
8144 KB |
Output is correct |
13 |
Correct |
1507 ms |
7348 KB |
Output is correct |
14 |
Correct |
1504 ms |
7736 KB |
Output is correct |
15 |
Correct |
1465 ms |
8516 KB |
Output is correct |
16 |
Correct |
1538 ms |
7540 KB |
Output is correct |
17 |
Correct |
1530 ms |
7436 KB |
Output is correct |
18 |
Correct |
1443 ms |
9360 KB |
Output is correct |
19 |
Correct |
1515 ms |
6680 KB |
Output is correct |
20 |
Correct |
1489 ms |
8112 KB |
Output is correct |
21 |
Correct |
1514 ms |
8784 KB |
Output is correct |
22 |
Correct |
1627 ms |
8544 KB |
Output is correct |
23 |
Correct |
1719 ms |
7632 KB |
Output is correct |
24 |
Correct |
1554 ms |
7684 KB |
Output is correct |
25 |
Correct |
1576 ms |
9408 KB |
Output is correct |
26 |
Correct |
1639 ms |
7940 KB |
Output is correct |
27 |
Correct |
1648 ms |
7888 KB |
Output is correct |
28 |
Correct |
1502 ms |
10688 KB |
Output is correct |
29 |
Correct |
1587 ms |
6712 KB |
Output is correct |
30 |
Correct |
1544 ms |
8556 KB |
Output is correct |
31 |
Correct |
1569 ms |
8592 KB |
Output is correct |
32 |
Correct |
1562 ms |
8512 KB |
Output is correct |
33 |
Correct |
1571 ms |
7512 KB |
Output is correct |
34 |
Correct |
1631 ms |
7508 KB |
Output is correct |
35 |
Correct |
1574 ms |
7980 KB |
Output is correct |
36 |
Correct |
1486 ms |
6540 KB |
Output is correct |
37 |
Correct |
1521 ms |
8460 KB |
Output is correct |
38 |
Correct |
1581 ms |
6560 KB |
Output is correct |
39 |
Correct |
1544 ms |
7720 KB |
Output is correct |
40 |
Correct |
1578 ms |
7660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
3 ms |
4444 KB |
Output is correct |
11 |
Correct |
155 ms |
12884 KB |
Output is correct |
12 |
Correct |
155 ms |
12976 KB |
Output is correct |
13 |
Correct |
167 ms |
12664 KB |
Output is correct |
14 |
Correct |
162 ms |
13044 KB |
Output is correct |
15 |
Correct |
184 ms |
12916 KB |
Output is correct |
16 |
Correct |
158 ms |
12884 KB |
Output is correct |
17 |
Correct |
161 ms |
12720 KB |
Output is correct |
18 |
Correct |
160 ms |
12916 KB |
Output is correct |
19 |
Correct |
157 ms |
12724 KB |
Output is correct |
20 |
Correct |
155 ms |
12976 KB |
Output is correct |
21 |
Correct |
184 ms |
12840 KB |
Output is correct |
22 |
Correct |
163 ms |
12880 KB |
Output is correct |
23 |
Correct |
151 ms |
12720 KB |
Output is correct |
24 |
Correct |
176 ms |
12988 KB |
Output is correct |
25 |
Correct |
162 ms |
12908 KB |
Output is correct |
26 |
Correct |
178 ms |
12820 KB |
Output is correct |
27 |
Correct |
165 ms |
13140 KB |
Output is correct |
28 |
Correct |
157 ms |
12716 KB |
Output is correct |
29 |
Correct |
157 ms |
12740 KB |
Output is correct |
30 |
Correct |
162 ms |
12716 KB |
Output is correct |
31 |
Correct |
154 ms |
12728 KB |
Output is correct |
32 |
Correct |
176 ms |
12932 KB |
Output is correct |
33 |
Correct |
205 ms |
12916 KB |
Output is correct |
34 |
Correct |
149 ms |
13000 KB |
Output is correct |
35 |
Correct |
164 ms |
12720 KB |
Output is correct |
36 |
Correct |
161 ms |
12880 KB |
Output is correct |
37 |
Correct |
167 ms |
12904 KB |
Output is correct |
38 |
Correct |
159 ms |
12908 KB |
Output is correct |
39 |
Correct |
162 ms |
12916 KB |
Output is correct |
40 |
Correct |
169 ms |
12976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
5 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
3 ms |
4444 KB |
Output is correct |
11 |
Correct |
1478 ms |
8608 KB |
Output is correct |
12 |
Correct |
1507 ms |
8144 KB |
Output is correct |
13 |
Correct |
1507 ms |
7348 KB |
Output is correct |
14 |
Correct |
1504 ms |
7736 KB |
Output is correct |
15 |
Correct |
1465 ms |
8516 KB |
Output is correct |
16 |
Correct |
1538 ms |
7540 KB |
Output is correct |
17 |
Correct |
1530 ms |
7436 KB |
Output is correct |
18 |
Correct |
1443 ms |
9360 KB |
Output is correct |
19 |
Correct |
1515 ms |
6680 KB |
Output is correct |
20 |
Correct |
1489 ms |
8112 KB |
Output is correct |
21 |
Correct |
1514 ms |
8784 KB |
Output is correct |
22 |
Correct |
1627 ms |
8544 KB |
Output is correct |
23 |
Correct |
1719 ms |
7632 KB |
Output is correct |
24 |
Correct |
1554 ms |
7684 KB |
Output is correct |
25 |
Correct |
1576 ms |
9408 KB |
Output is correct |
26 |
Correct |
1639 ms |
7940 KB |
Output is correct |
27 |
Correct |
1648 ms |
7888 KB |
Output is correct |
28 |
Correct |
1502 ms |
10688 KB |
Output is correct |
29 |
Correct |
1587 ms |
6712 KB |
Output is correct |
30 |
Correct |
1544 ms |
8556 KB |
Output is correct |
31 |
Correct |
1569 ms |
8592 KB |
Output is correct |
32 |
Correct |
1562 ms |
8512 KB |
Output is correct |
33 |
Correct |
1571 ms |
7512 KB |
Output is correct |
34 |
Correct |
1631 ms |
7508 KB |
Output is correct |
35 |
Correct |
1574 ms |
7980 KB |
Output is correct |
36 |
Correct |
1486 ms |
6540 KB |
Output is correct |
37 |
Correct |
1521 ms |
8460 KB |
Output is correct |
38 |
Correct |
1581 ms |
6560 KB |
Output is correct |
39 |
Correct |
1544 ms |
7720 KB |
Output is correct |
40 |
Correct |
1578 ms |
7660 KB |
Output is correct |
41 |
Correct |
155 ms |
12884 KB |
Output is correct |
42 |
Correct |
155 ms |
12976 KB |
Output is correct |
43 |
Correct |
167 ms |
12664 KB |
Output is correct |
44 |
Correct |
162 ms |
13044 KB |
Output is correct |
45 |
Correct |
184 ms |
12916 KB |
Output is correct |
46 |
Correct |
158 ms |
12884 KB |
Output is correct |
47 |
Correct |
161 ms |
12720 KB |
Output is correct |
48 |
Correct |
160 ms |
12916 KB |
Output is correct |
49 |
Correct |
157 ms |
12724 KB |
Output is correct |
50 |
Correct |
155 ms |
12976 KB |
Output is correct |
51 |
Correct |
184 ms |
12840 KB |
Output is correct |
52 |
Correct |
163 ms |
12880 KB |
Output is correct |
53 |
Correct |
151 ms |
12720 KB |
Output is correct |
54 |
Correct |
176 ms |
12988 KB |
Output is correct |
55 |
Correct |
162 ms |
12908 KB |
Output is correct |
56 |
Correct |
178 ms |
12820 KB |
Output is correct |
57 |
Correct |
165 ms |
13140 KB |
Output is correct |
58 |
Correct |
157 ms |
12716 KB |
Output is correct |
59 |
Correct |
157 ms |
12740 KB |
Output is correct |
60 |
Correct |
162 ms |
12716 KB |
Output is correct |
61 |
Correct |
154 ms |
12728 KB |
Output is correct |
62 |
Correct |
176 ms |
12932 KB |
Output is correct |
63 |
Correct |
205 ms |
12916 KB |
Output is correct |
64 |
Correct |
149 ms |
13000 KB |
Output is correct |
65 |
Correct |
164 ms |
12720 KB |
Output is correct |
66 |
Correct |
161 ms |
12880 KB |
Output is correct |
67 |
Correct |
167 ms |
12904 KB |
Output is correct |
68 |
Correct |
159 ms |
12908 KB |
Output is correct |
69 |
Correct |
162 ms |
12916 KB |
Output is correct |
70 |
Correct |
169 ms |
12976 KB |
Output is correct |
71 |
Correct |
1900 ms |
17808 KB |
Output is correct |
72 |
Correct |
1819 ms |
18040 KB |
Output is correct |
73 |
Correct |
1925 ms |
16504 KB |
Output is correct |
74 |
Correct |
1981 ms |
38220 KB |
Output is correct |
75 |
Correct |
1856 ms |
40036 KB |
Output is correct |
76 |
Execution timed out |
2003 ms |
38736 KB |
Time limit exceeded |
77 |
Halted |
0 ms |
0 KB |
- |