#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<
#define INF (ll)1e18
#define mod 998244353
#define maxn 1048586
ll i, i1, j, k, k1, tc, n, m, res, flag[10], a, b;
ll dp[2][maxn], cn[3], l, q, mk, ma;
string s, t;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#if !ONLINE_JUDGE && !EVAL
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif
cin >> l >> q >> s;
for (mk = 0; mk < (1 << l); mk++) {
dp[0][mk] = (ll)s[mk] - '0';
dp[1][mk] = (ll)s[mk ^ ((1 << l) - 1)] - '0';
}
for (i = 0; i < l; i++) {
for (mk = 0; mk < (1 << l); mk++) {
if ((mk >> i) & 1) {
dp[0][mk] += dp[0][mk ^ (1 << i)];
dp[1][mk] += dp[1][mk ^ (1 << i)];
}
}
}
/* for (mk = 0; mk < (1 << l); mk++) {
cout << mk _ dp[0][mk] _ dp[1][mk] << nl;
} */
while (q--) {
cin >> t; cn[0] = 0; cn[1] = 0; cn[2] = 0; res = 0;
k = 0; m = 0;
reverse(t.begin(), t.end());
for (i = 0; i < l; i++) {
if (t[i] == '0') cn[0]++;
else if (t[i] == '1') cn[1]++;
else cn[2]++;
}
if (cn[0] <= 6) {
// cout << "t = " << t << nl;
for (i = 0; i < l; i++) {
if (t[i] == '?') k += (1 << i);
else if (t[i] == '0') m += (1 << i);
}
for (ma = m;; ma = (ma - 1) & m) {
// cout << "k, ma = " << k _ ma _ k + ma << nl;
res += (dp[1][k + ma] * (1 - 2 * (__builtin_popcount(m ^ ma) % 2)));
if (ma == 0) break;
}
} else if (cn[1] <= 6) {
for (i = 0; i < l; i++) {
if (t[i] == '?') k += (1 << i);
else if (t[i] == '1') m += (1 << i);
}
for (ma = m;; ma = (ma - 1) & m) {
res += (dp[0][k + ma] * (1 - 2 * (__builtin_popcount(m ^ ma) % 2)));
if (ma == 0) break;
}
} else {
for (i = 0; i < l; i++) {
if (t[i] == '1') k += (1 << i);
else if (t[i] == '?') m += (1 << i);
}
for (ma = m;; ma = (ma - 1) & m) {
res += (ll)s[k + ma] - '0';
if (ma == 0) break;
}
}
cout << res << nl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
268 ms |
15020 KB |
Output is correct |
12 |
Correct |
397 ms |
14824 KB |
Output is correct |
13 |
Correct |
487 ms |
14032 KB |
Output is correct |
14 |
Correct |
410 ms |
14144 KB |
Output is correct |
15 |
Correct |
333 ms |
15196 KB |
Output is correct |
16 |
Correct |
387 ms |
14152 KB |
Output is correct |
17 |
Correct |
434 ms |
14172 KB |
Output is correct |
18 |
Correct |
225 ms |
16032 KB |
Output is correct |
19 |
Correct |
406 ms |
13004 KB |
Output is correct |
20 |
Correct |
301 ms |
14916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
268 ms |
15020 KB |
Output is correct |
12 |
Correct |
397 ms |
14824 KB |
Output is correct |
13 |
Correct |
487 ms |
14032 KB |
Output is correct |
14 |
Correct |
410 ms |
14144 KB |
Output is correct |
15 |
Correct |
333 ms |
15196 KB |
Output is correct |
16 |
Correct |
387 ms |
14152 KB |
Output is correct |
17 |
Correct |
434 ms |
14172 KB |
Output is correct |
18 |
Correct |
225 ms |
16032 KB |
Output is correct |
19 |
Correct |
406 ms |
13004 KB |
Output is correct |
20 |
Correct |
301 ms |
14916 KB |
Output is correct |
21 |
Correct |
328 ms |
18064 KB |
Output is correct |
22 |
Correct |
430 ms |
18372 KB |
Output is correct |
23 |
Correct |
701 ms |
17220 KB |
Output is correct |
24 |
Correct |
574 ms |
17092 KB |
Output is correct |
25 |
Correct |
410 ms |
19052 KB |
Output is correct |
26 |
Correct |
508 ms |
17548 KB |
Output is correct |
27 |
Correct |
531 ms |
17532 KB |
Output is correct |
28 |
Correct |
244 ms |
20168 KB |
Output is correct |
29 |
Correct |
606 ms |
16144 KB |
Output is correct |
30 |
Correct |
365 ms |
18300 KB |
Output is correct |
31 |
Correct |
489 ms |
18116 KB |
Output is correct |
32 |
Correct |
495 ms |
18164 KB |
Output is correct |
33 |
Correct |
393 ms |
16964 KB |
Output is correct |
34 |
Correct |
523 ms |
17112 KB |
Output is correct |
35 |
Correct |
520 ms |
17716 KB |
Output is correct |
36 |
Correct |
253 ms |
16132 KB |
Output is correct |
37 |
Correct |
323 ms |
18148 KB |
Output is correct |
38 |
Correct |
542 ms |
16200 KB |
Output is correct |
39 |
Correct |
479 ms |
17316 KB |
Output is correct |
40 |
Correct |
479 ms |
17088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
78 ms |
20084 KB |
Output is correct |
12 |
Correct |
78 ms |
20168 KB |
Output is correct |
13 |
Correct |
99 ms |
20032 KB |
Output is correct |
14 |
Correct |
128 ms |
20028 KB |
Output is correct |
15 |
Correct |
84 ms |
20160 KB |
Output is correct |
16 |
Correct |
132 ms |
20068 KB |
Output is correct |
17 |
Correct |
122 ms |
20012 KB |
Output is correct |
18 |
Correct |
64 ms |
20304 KB |
Output is correct |
19 |
Correct |
76 ms |
19936 KB |
Output is correct |
20 |
Correct |
79 ms |
20092 KB |
Output is correct |
21 |
Correct |
102 ms |
20172 KB |
Output is correct |
22 |
Correct |
129 ms |
20040 KB |
Output is correct |
23 |
Correct |
80 ms |
20068 KB |
Output is correct |
24 |
Correct |
129 ms |
20172 KB |
Output is correct |
25 |
Correct |
127 ms |
20076 KB |
Output is correct |
26 |
Correct |
67 ms |
19940 KB |
Output is correct |
27 |
Correct |
73 ms |
20088 KB |
Output is correct |
28 |
Correct |
77 ms |
19972 KB |
Output is correct |
29 |
Correct |
97 ms |
20068 KB |
Output is correct |
30 |
Correct |
83 ms |
20124 KB |
Output is correct |
31 |
Correct |
80 ms |
20036 KB |
Output is correct |
32 |
Correct |
146 ms |
20048 KB |
Output is correct |
33 |
Correct |
123 ms |
20136 KB |
Output is correct |
34 |
Correct |
64 ms |
19900 KB |
Output is correct |
35 |
Correct |
104 ms |
20092 KB |
Output is correct |
36 |
Correct |
110 ms |
20108 KB |
Output is correct |
37 |
Correct |
106 ms |
20120 KB |
Output is correct |
38 |
Correct |
104 ms |
20044 KB |
Output is correct |
39 |
Correct |
110 ms |
20044 KB |
Output is correct |
40 |
Correct |
103 ms |
20048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
268 ms |
15020 KB |
Output is correct |
12 |
Correct |
397 ms |
14824 KB |
Output is correct |
13 |
Correct |
487 ms |
14032 KB |
Output is correct |
14 |
Correct |
410 ms |
14144 KB |
Output is correct |
15 |
Correct |
333 ms |
15196 KB |
Output is correct |
16 |
Correct |
387 ms |
14152 KB |
Output is correct |
17 |
Correct |
434 ms |
14172 KB |
Output is correct |
18 |
Correct |
225 ms |
16032 KB |
Output is correct |
19 |
Correct |
406 ms |
13004 KB |
Output is correct |
20 |
Correct |
301 ms |
14916 KB |
Output is correct |
21 |
Correct |
328 ms |
18064 KB |
Output is correct |
22 |
Correct |
430 ms |
18372 KB |
Output is correct |
23 |
Correct |
701 ms |
17220 KB |
Output is correct |
24 |
Correct |
574 ms |
17092 KB |
Output is correct |
25 |
Correct |
410 ms |
19052 KB |
Output is correct |
26 |
Correct |
508 ms |
17548 KB |
Output is correct |
27 |
Correct |
531 ms |
17532 KB |
Output is correct |
28 |
Correct |
244 ms |
20168 KB |
Output is correct |
29 |
Correct |
606 ms |
16144 KB |
Output is correct |
30 |
Correct |
365 ms |
18300 KB |
Output is correct |
31 |
Correct |
489 ms |
18116 KB |
Output is correct |
32 |
Correct |
495 ms |
18164 KB |
Output is correct |
33 |
Correct |
393 ms |
16964 KB |
Output is correct |
34 |
Correct |
523 ms |
17112 KB |
Output is correct |
35 |
Correct |
520 ms |
17716 KB |
Output is correct |
36 |
Correct |
253 ms |
16132 KB |
Output is correct |
37 |
Correct |
323 ms |
18148 KB |
Output is correct |
38 |
Correct |
542 ms |
16200 KB |
Output is correct |
39 |
Correct |
479 ms |
17316 KB |
Output is correct |
40 |
Correct |
479 ms |
17088 KB |
Output is correct |
41 |
Correct |
78 ms |
20084 KB |
Output is correct |
42 |
Correct |
78 ms |
20168 KB |
Output is correct |
43 |
Correct |
99 ms |
20032 KB |
Output is correct |
44 |
Correct |
128 ms |
20028 KB |
Output is correct |
45 |
Correct |
84 ms |
20160 KB |
Output is correct |
46 |
Correct |
132 ms |
20068 KB |
Output is correct |
47 |
Correct |
122 ms |
20012 KB |
Output is correct |
48 |
Correct |
64 ms |
20304 KB |
Output is correct |
49 |
Correct |
76 ms |
19936 KB |
Output is correct |
50 |
Correct |
79 ms |
20092 KB |
Output is correct |
51 |
Correct |
102 ms |
20172 KB |
Output is correct |
52 |
Correct |
129 ms |
20040 KB |
Output is correct |
53 |
Correct |
80 ms |
20068 KB |
Output is correct |
54 |
Correct |
129 ms |
20172 KB |
Output is correct |
55 |
Correct |
127 ms |
20076 KB |
Output is correct |
56 |
Correct |
67 ms |
19940 KB |
Output is correct |
57 |
Correct |
73 ms |
20088 KB |
Output is correct |
58 |
Correct |
77 ms |
19972 KB |
Output is correct |
59 |
Correct |
97 ms |
20068 KB |
Output is correct |
60 |
Correct |
83 ms |
20124 KB |
Output is correct |
61 |
Correct |
80 ms |
20036 KB |
Output is correct |
62 |
Correct |
146 ms |
20048 KB |
Output is correct |
63 |
Correct |
123 ms |
20136 KB |
Output is correct |
64 |
Correct |
64 ms |
19900 KB |
Output is correct |
65 |
Correct |
104 ms |
20092 KB |
Output is correct |
66 |
Correct |
110 ms |
20108 KB |
Output is correct |
67 |
Correct |
106 ms |
20120 KB |
Output is correct |
68 |
Correct |
104 ms |
20044 KB |
Output is correct |
69 |
Correct |
110 ms |
20044 KB |
Output is correct |
70 |
Correct |
103 ms |
20048 KB |
Output is correct |
71 |
Correct |
547 ms |
26700 KB |
Output is correct |
72 |
Correct |
626 ms |
26732 KB |
Output is correct |
73 |
Correct |
962 ms |
25444 KB |
Output is correct |
74 |
Correct |
1861 ms |
25684 KB |
Output is correct |
75 |
Correct |
669 ms |
28008 KB |
Output is correct |
76 |
Correct |
1710 ms |
26064 KB |
Output is correct |
77 |
Correct |
1479 ms |
25876 KB |
Output is correct |
78 |
Correct |
339 ms |
29796 KB |
Output is correct |
79 |
Correct |
514 ms |
23632 KB |
Output is correct |
80 |
Correct |
589 ms |
26848 KB |
Output is correct |
81 |
Correct |
1062 ms |
26852 KB |
Output is correct |
82 |
Correct |
1775 ms |
25608 KB |
Output is correct |
83 |
Correct |
658 ms |
24884 KB |
Output is correct |
84 |
Correct |
1571 ms |
25764 KB |
Output is correct |
85 |
Correct |
1503 ms |
25732 KB |
Output is correct |
86 |
Correct |
359 ms |
23528 KB |
Output is correct |
87 |
Correct |
561 ms |
26444 KB |
Output is correct |
88 |
Correct |
578 ms |
23552 KB |
Output is correct |
89 |
Correct |
956 ms |
25064 KB |
Output is correct |
90 |
Correct |
744 ms |
25444 KB |
Output is correct |
91 |
Correct |
675 ms |
24636 KB |
Output is correct |
92 |
Correct |
1918 ms |
25760 KB |
Output is correct |
93 |
Correct |
1427 ms |
25520 KB |
Output is correct |
94 |
Correct |
373 ms |
23344 KB |
Output is correct |
95 |
Correct |
1166 ms |
25384 KB |
Output is correct |
96 |
Correct |
1185 ms |
25448 KB |
Output is correct |
97 |
Correct |
1176 ms |
25456 KB |
Output is correct |
98 |
Correct |
1185 ms |
25268 KB |
Output is correct |
99 |
Correct |
1221 ms |
25000 KB |
Output is correct |
100 |
Correct |
1165 ms |
24936 KB |
Output is correct |