#include <bits/stdc++.h>
using namespace std;
const int B = 13, N = 1<<20, SZ = pow(3, B);
int Q, dp[SZ], ans[N], id[N], p3[B] = {1};
string A, inp;
short x[N], y[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
for(int i = 1; i < B; ++i)
p3[i] = p3[i-1] * 3;
cin >> Q >> Q >> A;
A.resize(N, '0');
for(int i = 0; i < Q; ++i) {
cin >> inp;
reverse(begin(inp), end(inp));
inp.resize(20, '0');
for(int k = 0; k < B; ++k)
id[i] += p3[k] * ((48 < inp[k]) + (62 < inp[k]));
for(int k = 0; k < 20-B; ++k) {
if(inp[k+B] != '?') y[i] |= 1<<k;
if(inp[k+B] == '1') x[i] |= 1<<k;
}
}
for(int s = 0; s < (1<<(20-B)); ++s) {
memset(dp, 0, sizeof dp);
for(int i = 0; i < (1<<B); ++i) {
int j = 0;
for(int k = 0; k < B; ++k)
if(i & (1<<k)) j += p3[k];
dp[j] += A[i | (s << B)] - '0';
}
for(int i = 1; i < SZ; ++i) {
int j = -1, pw = 1;
for(int k = 0, p = i; k < B; ++k, p /= 3)
if((p % 3) > 1) j = k, pw = p3[k], k = B;
if(j >= 0)
dp[i] = dp[i - pw] + dp[i - 2 * pw];
}
for(int i = 0; i < Q; ++i)
if(!((x[i] ^ s) & y[i]))
ans[i] += dp[id[i]];
}
for(int i = 0; i < Q; ++i)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1048 ms |
7628 KB |
Output is correct |
2 |
Correct |
1039 ms |
7628 KB |
Output is correct |
3 |
Correct |
1016 ms |
7628 KB |
Output is correct |
4 |
Correct |
1035 ms |
7636 KB |
Output is correct |
5 |
Correct |
1058 ms |
7628 KB |
Output is correct |
6 |
Correct |
967 ms |
7748 KB |
Output is correct |
7 |
Correct |
971 ms |
7628 KB |
Output is correct |
8 |
Correct |
987 ms |
7748 KB |
Output is correct |
9 |
Correct |
977 ms |
7628 KB |
Output is correct |
10 |
Correct |
986 ms |
7628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1048 ms |
7628 KB |
Output is correct |
2 |
Correct |
1039 ms |
7628 KB |
Output is correct |
3 |
Correct |
1016 ms |
7628 KB |
Output is correct |
4 |
Correct |
1035 ms |
7636 KB |
Output is correct |
5 |
Correct |
1058 ms |
7628 KB |
Output is correct |
6 |
Correct |
967 ms |
7748 KB |
Output is correct |
7 |
Correct |
971 ms |
7628 KB |
Output is correct |
8 |
Correct |
987 ms |
7748 KB |
Output is correct |
9 |
Correct |
977 ms |
7628 KB |
Output is correct |
10 |
Correct |
986 ms |
7628 KB |
Output is correct |
11 |
Correct |
1296 ms |
24772 KB |
Output is correct |
12 |
Correct |
1343 ms |
24388 KB |
Output is correct |
13 |
Correct |
1312 ms |
23504 KB |
Output is correct |
14 |
Correct |
1310 ms |
23776 KB |
Output is correct |
15 |
Correct |
1342 ms |
24672 KB |
Output is correct |
16 |
Correct |
1329 ms |
23772 KB |
Output is correct |
17 |
Correct |
1296 ms |
23764 KB |
Output is correct |
18 |
Correct |
1317 ms |
25688 KB |
Output is correct |
19 |
Correct |
1290 ms |
22632 KB |
Output is correct |
20 |
Correct |
1319 ms |
24376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1048 ms |
7628 KB |
Output is correct |
2 |
Correct |
1039 ms |
7628 KB |
Output is correct |
3 |
Correct |
1016 ms |
7628 KB |
Output is correct |
4 |
Correct |
1035 ms |
7636 KB |
Output is correct |
5 |
Correct |
1058 ms |
7628 KB |
Output is correct |
6 |
Correct |
967 ms |
7748 KB |
Output is correct |
7 |
Correct |
971 ms |
7628 KB |
Output is correct |
8 |
Correct |
987 ms |
7748 KB |
Output is correct |
9 |
Correct |
977 ms |
7628 KB |
Output is correct |
10 |
Correct |
986 ms |
7628 KB |
Output is correct |
11 |
Correct |
1296 ms |
24772 KB |
Output is correct |
12 |
Correct |
1343 ms |
24388 KB |
Output is correct |
13 |
Correct |
1312 ms |
23504 KB |
Output is correct |
14 |
Correct |
1310 ms |
23776 KB |
Output is correct |
15 |
Correct |
1342 ms |
24672 KB |
Output is correct |
16 |
Correct |
1329 ms |
23772 KB |
Output is correct |
17 |
Correct |
1296 ms |
23764 KB |
Output is correct |
18 |
Correct |
1317 ms |
25688 KB |
Output is correct |
19 |
Correct |
1290 ms |
22632 KB |
Output is correct |
20 |
Correct |
1319 ms |
24376 KB |
Output is correct |
21 |
Correct |
1305 ms |
24592 KB |
Output is correct |
22 |
Correct |
1301 ms |
24688 KB |
Output is correct |
23 |
Correct |
1303 ms |
23772 KB |
Output is correct |
24 |
Correct |
1305 ms |
23532 KB |
Output is correct |
25 |
Correct |
1298 ms |
25668 KB |
Output is correct |
26 |
Correct |
1310 ms |
24052 KB |
Output is correct |
27 |
Correct |
1340 ms |
24184 KB |
Output is correct |
28 |
Correct |
1296 ms |
26604 KB |
Output is correct |
29 |
Correct |
1310 ms |
22512 KB |
Output is correct |
30 |
Correct |
1305 ms |
24776 KB |
Output is correct |
31 |
Correct |
1323 ms |
24604 KB |
Output is correct |
32 |
Correct |
1300 ms |
24568 KB |
Output is correct |
33 |
Correct |
1297 ms |
23408 KB |
Output is correct |
34 |
Correct |
1315 ms |
23572 KB |
Output is correct |
35 |
Correct |
1306 ms |
24052 KB |
Output is correct |
36 |
Correct |
1334 ms |
22520 KB |
Output is correct |
37 |
Correct |
1305 ms |
24580 KB |
Output is correct |
38 |
Correct |
1289 ms |
22568 KB |
Output is correct |
39 |
Correct |
1315 ms |
23820 KB |
Output is correct |
40 |
Correct |
1294 ms |
23284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1048 ms |
7628 KB |
Output is correct |
2 |
Correct |
1039 ms |
7628 KB |
Output is correct |
3 |
Correct |
1016 ms |
7628 KB |
Output is correct |
4 |
Correct |
1035 ms |
7636 KB |
Output is correct |
5 |
Correct |
1058 ms |
7628 KB |
Output is correct |
6 |
Correct |
967 ms |
7748 KB |
Output is correct |
7 |
Correct |
971 ms |
7628 KB |
Output is correct |
8 |
Correct |
987 ms |
7748 KB |
Output is correct |
9 |
Correct |
977 ms |
7628 KB |
Output is correct |
10 |
Correct |
986 ms |
7628 KB |
Output is correct |
11 |
Correct |
1018 ms |
9852 KB |
Output is correct |
12 |
Correct |
1050 ms |
9880 KB |
Output is correct |
13 |
Correct |
1022 ms |
9960 KB |
Output is correct |
14 |
Correct |
1020 ms |
9856 KB |
Output is correct |
15 |
Correct |
1022 ms |
9956 KB |
Output is correct |
16 |
Correct |
999 ms |
9852 KB |
Output is correct |
17 |
Correct |
1029 ms |
9952 KB |
Output is correct |
18 |
Correct |
1000 ms |
9912 KB |
Output is correct |
19 |
Correct |
1022 ms |
9732 KB |
Output is correct |
20 |
Correct |
1025 ms |
9984 KB |
Output is correct |
21 |
Correct |
1146 ms |
9852 KB |
Output is correct |
22 |
Correct |
1105 ms |
9724 KB |
Output is correct |
23 |
Correct |
1198 ms |
9732 KB |
Output is correct |
24 |
Correct |
1107 ms |
9728 KB |
Output is correct |
25 |
Correct |
1122 ms |
9728 KB |
Output is correct |
26 |
Correct |
1080 ms |
9772 KB |
Output is correct |
27 |
Correct |
1119 ms |
9752 KB |
Output is correct |
28 |
Correct |
1024 ms |
9732 KB |
Output is correct |
29 |
Correct |
1024 ms |
9856 KB |
Output is correct |
30 |
Correct |
1033 ms |
9860 KB |
Output is correct |
31 |
Correct |
1046 ms |
9864 KB |
Output is correct |
32 |
Correct |
1030 ms |
9856 KB |
Output is correct |
33 |
Correct |
1016 ms |
9856 KB |
Output is correct |
34 |
Correct |
994 ms |
9624 KB |
Output is correct |
35 |
Correct |
1020 ms |
9724 KB |
Output is correct |
36 |
Correct |
1025 ms |
9728 KB |
Output is correct |
37 |
Correct |
1020 ms |
9724 KB |
Output is correct |
38 |
Correct |
1051 ms |
9728 KB |
Output is correct |
39 |
Correct |
1024 ms |
9828 KB |
Output is correct |
40 |
Correct |
1042 ms |
9728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1048 ms |
7628 KB |
Output is correct |
2 |
Correct |
1039 ms |
7628 KB |
Output is correct |
3 |
Correct |
1016 ms |
7628 KB |
Output is correct |
4 |
Correct |
1035 ms |
7636 KB |
Output is correct |
5 |
Correct |
1058 ms |
7628 KB |
Output is correct |
6 |
Correct |
967 ms |
7748 KB |
Output is correct |
7 |
Correct |
971 ms |
7628 KB |
Output is correct |
8 |
Correct |
987 ms |
7748 KB |
Output is correct |
9 |
Correct |
977 ms |
7628 KB |
Output is correct |
10 |
Correct |
986 ms |
7628 KB |
Output is correct |
11 |
Correct |
1296 ms |
24772 KB |
Output is correct |
12 |
Correct |
1343 ms |
24388 KB |
Output is correct |
13 |
Correct |
1312 ms |
23504 KB |
Output is correct |
14 |
Correct |
1310 ms |
23776 KB |
Output is correct |
15 |
Correct |
1342 ms |
24672 KB |
Output is correct |
16 |
Correct |
1329 ms |
23772 KB |
Output is correct |
17 |
Correct |
1296 ms |
23764 KB |
Output is correct |
18 |
Correct |
1317 ms |
25688 KB |
Output is correct |
19 |
Correct |
1290 ms |
22632 KB |
Output is correct |
20 |
Correct |
1319 ms |
24376 KB |
Output is correct |
21 |
Correct |
1305 ms |
24592 KB |
Output is correct |
22 |
Correct |
1301 ms |
24688 KB |
Output is correct |
23 |
Correct |
1303 ms |
23772 KB |
Output is correct |
24 |
Correct |
1305 ms |
23532 KB |
Output is correct |
25 |
Correct |
1298 ms |
25668 KB |
Output is correct |
26 |
Correct |
1310 ms |
24052 KB |
Output is correct |
27 |
Correct |
1340 ms |
24184 KB |
Output is correct |
28 |
Correct |
1296 ms |
26604 KB |
Output is correct |
29 |
Correct |
1310 ms |
22512 KB |
Output is correct |
30 |
Correct |
1305 ms |
24776 KB |
Output is correct |
31 |
Correct |
1323 ms |
24604 KB |
Output is correct |
32 |
Correct |
1300 ms |
24568 KB |
Output is correct |
33 |
Correct |
1297 ms |
23408 KB |
Output is correct |
34 |
Correct |
1315 ms |
23572 KB |
Output is correct |
35 |
Correct |
1306 ms |
24052 KB |
Output is correct |
36 |
Correct |
1334 ms |
22520 KB |
Output is correct |
37 |
Correct |
1305 ms |
24580 KB |
Output is correct |
38 |
Correct |
1289 ms |
22568 KB |
Output is correct |
39 |
Correct |
1315 ms |
23820 KB |
Output is correct |
40 |
Correct |
1294 ms |
23284 KB |
Output is correct |
41 |
Correct |
1018 ms |
9852 KB |
Output is correct |
42 |
Correct |
1050 ms |
9880 KB |
Output is correct |
43 |
Correct |
1022 ms |
9960 KB |
Output is correct |
44 |
Correct |
1020 ms |
9856 KB |
Output is correct |
45 |
Correct |
1022 ms |
9956 KB |
Output is correct |
46 |
Correct |
999 ms |
9852 KB |
Output is correct |
47 |
Correct |
1029 ms |
9952 KB |
Output is correct |
48 |
Correct |
1000 ms |
9912 KB |
Output is correct |
49 |
Correct |
1022 ms |
9732 KB |
Output is correct |
50 |
Correct |
1025 ms |
9984 KB |
Output is correct |
51 |
Correct |
1146 ms |
9852 KB |
Output is correct |
52 |
Correct |
1105 ms |
9724 KB |
Output is correct |
53 |
Correct |
1198 ms |
9732 KB |
Output is correct |
54 |
Correct |
1107 ms |
9728 KB |
Output is correct |
55 |
Correct |
1122 ms |
9728 KB |
Output is correct |
56 |
Correct |
1080 ms |
9772 KB |
Output is correct |
57 |
Correct |
1119 ms |
9752 KB |
Output is correct |
58 |
Correct |
1024 ms |
9732 KB |
Output is correct |
59 |
Correct |
1024 ms |
9856 KB |
Output is correct |
60 |
Correct |
1033 ms |
9860 KB |
Output is correct |
61 |
Correct |
1046 ms |
9864 KB |
Output is correct |
62 |
Correct |
1030 ms |
9856 KB |
Output is correct |
63 |
Correct |
1016 ms |
9856 KB |
Output is correct |
64 |
Correct |
994 ms |
9624 KB |
Output is correct |
65 |
Correct |
1020 ms |
9724 KB |
Output is correct |
66 |
Correct |
1025 ms |
9728 KB |
Output is correct |
67 |
Correct |
1020 ms |
9724 KB |
Output is correct |
68 |
Correct |
1051 ms |
9728 KB |
Output is correct |
69 |
Correct |
1024 ms |
9828 KB |
Output is correct |
70 |
Correct |
1042 ms |
9728 KB |
Output is correct |
71 |
Correct |
1512 ms |
25572 KB |
Output is correct |
72 |
Correct |
1523 ms |
23416 KB |
Output is correct |
73 |
Correct |
1543 ms |
23912 KB |
Output is correct |
74 |
Correct |
1626 ms |
24224 KB |
Output is correct |
75 |
Correct |
1685 ms |
26268 KB |
Output is correct |
76 |
Correct |
1635 ms |
24460 KB |
Output is correct |
77 |
Correct |
1666 ms |
24368 KB |
Output is correct |
78 |
Correct |
1338 ms |
24392 KB |
Output is correct |
79 |
Correct |
1442 ms |
22244 KB |
Output is correct |
80 |
Correct |
1545 ms |
25312 KB |
Output is correct |
81 |
Correct |
1714 ms |
25316 KB |
Output is correct |
82 |
Correct |
1611 ms |
24296 KB |
Output is correct |
83 |
Correct |
1458 ms |
23436 KB |
Output is correct |
84 |
Correct |
1585 ms |
24292 KB |
Output is correct |
85 |
Correct |
1637 ms |
24320 KB |
Output is correct |
86 |
Correct |
1316 ms |
22244 KB |
Output is correct |
87 |
Correct |
1494 ms |
23304 KB |
Output is correct |
88 |
Correct |
1437 ms |
22160 KB |
Output is correct |
89 |
Correct |
1522 ms |
23692 KB |
Output is correct |
90 |
Correct |
1580 ms |
24076 KB |
Output is correct |
91 |
Correct |
1418 ms |
23184 KB |
Output is correct |
92 |
Correct |
1633 ms |
24288 KB |
Output is correct |
93 |
Correct |
1656 ms |
24080 KB |
Output is correct |
94 |
Correct |
1298 ms |
19940 KB |
Output is correct |
95 |
Correct |
1605 ms |
24016 KB |
Output is correct |
96 |
Correct |
1600 ms |
24176 KB |
Output is correct |
97 |
Correct |
1741 ms |
24080 KB |
Output is correct |
98 |
Correct |
1872 ms |
23892 KB |
Output is correct |
99 |
Correct |
1766 ms |
23940 KB |
Output is correct |
100 |
Correct |
1777 ms |
23952 KB |
Output is correct |