#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int l, q, a, b, c, sos[1 << 20], rsos[1 << 20];
string s, k;
int solve_a() { // Brute force over '?'
int ans = 0, base = 0, mask = 0;
FOR(i, 0, l) {
if (k[i] == '?') mask += 1 << i;
else if (k[i] == '1') base += 1 << i;
}
for (int i = mask; i; i = mask & (i - 1)) ans += s[i | base] - '0';
ans += s[base] - '0';
return ans;
}
int solve_b() { // Brute force over '0'
int ans = 0, base = 0, mask = 0;
FOR(i, 0, l) {
if (k[i] == '0') mask += 1 << i;
else if (k[i] == '?') base += 1 << i;
}
for (int i = mask; i; i = mask & (i - 1)) ans += ((b - __builtin_popcount(i)) & 1 ? -1 : 1) * rsos[i | base];
ans += (b & 1 ? -1 : 1) * rsos[base];
return ans;
}
int solve_c() { // Brute force over '1'
int ans = 0, base = 0, mask = 0;
FOR(i, 0, l) {
if (k[i] == '1') mask += 1 << i;
else if (k[i] == '?') base += 1 << i;
}
for (int i = mask; i; i = mask & (i - 1)) ans += ((c - __builtin_popcount(i)) & 1 ? -1 : 1) * sos[i | base];
ans += (c & 1 ? -1 : 1) * sos[base];
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> l >> q >> s;
FOR(i, 0, 1 << l) sos[i] = s[i] - '0', rsos[i] = s[(1 << l) - i - 1] - '0';
FOR(i, 0, l) FOR(j, 0, (1 << l)) if (j & (1 << i))
sos[j] += sos[j ^ (1 << i)], rsos[j] += rsos[j ^ (1 << i)];
while (q--) {
cin >> k;
reverse(k.begin(), k.end());
a = b = c = 0;
FOR(i, 0, l) {
if (k[i] == '?') a++;
if (k[i] == '0') b++;
if (k[i] == '1') c++;
}
if (a < 7) cout << solve_a() << '\n';
else if (b < 7) cout << solve_b() << '\n';
else cout << solve_c() << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
314 ms |
15124 KB |
Output is correct |
12 |
Correct |
321 ms |
14944 KB |
Output is correct |
13 |
Correct |
298 ms |
14072 KB |
Output is correct |
14 |
Correct |
302 ms |
14200 KB |
Output is correct |
15 |
Correct |
386 ms |
15480 KB |
Output is correct |
16 |
Correct |
352 ms |
14408 KB |
Output is correct |
17 |
Correct |
341 ms |
14328 KB |
Output is correct |
18 |
Correct |
221 ms |
16120 KB |
Output is correct |
19 |
Correct |
254 ms |
13096 KB |
Output is correct |
20 |
Correct |
321 ms |
14840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
314 ms |
15124 KB |
Output is correct |
12 |
Correct |
321 ms |
14944 KB |
Output is correct |
13 |
Correct |
298 ms |
14072 KB |
Output is correct |
14 |
Correct |
302 ms |
14200 KB |
Output is correct |
15 |
Correct |
386 ms |
15480 KB |
Output is correct |
16 |
Correct |
352 ms |
14408 KB |
Output is correct |
17 |
Correct |
341 ms |
14328 KB |
Output is correct |
18 |
Correct |
221 ms |
16120 KB |
Output is correct |
19 |
Correct |
254 ms |
13096 KB |
Output is correct |
20 |
Correct |
321 ms |
14840 KB |
Output is correct |
21 |
Correct |
300 ms |
18296 KB |
Output is correct |
22 |
Correct |
460 ms |
18376 KB |
Output is correct |
23 |
Correct |
378 ms |
17400 KB |
Output is correct |
24 |
Correct |
368 ms |
17144 KB |
Output is correct |
25 |
Correct |
384 ms |
19192 KB |
Output is correct |
26 |
Correct |
411 ms |
17656 KB |
Output is correct |
27 |
Correct |
408 ms |
17704 KB |
Output is correct |
28 |
Correct |
253 ms |
20216 KB |
Output is correct |
29 |
Correct |
282 ms |
16120 KB |
Output is correct |
30 |
Correct |
357 ms |
18552 KB |
Output is correct |
31 |
Correct |
464 ms |
18296 KB |
Output is correct |
32 |
Correct |
419 ms |
18296 KB |
Output is correct |
33 |
Correct |
330 ms |
17128 KB |
Output is correct |
34 |
Correct |
371 ms |
17272 KB |
Output is correct |
35 |
Correct |
408 ms |
17856 KB |
Output is correct |
36 |
Correct |
229 ms |
16120 KB |
Output is correct |
37 |
Correct |
412 ms |
18364 KB |
Output is correct |
38 |
Correct |
296 ms |
16248 KB |
Output is correct |
39 |
Correct |
385 ms |
17300 KB |
Output is correct |
40 |
Correct |
381 ms |
17144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
61 ms |
12060 KB |
Output is correct |
12 |
Correct |
59 ms |
12060 KB |
Output is correct |
13 |
Correct |
68 ms |
11928 KB |
Output is correct |
14 |
Correct |
77 ms |
11928 KB |
Output is correct |
15 |
Correct |
62 ms |
12056 KB |
Output is correct |
16 |
Correct |
75 ms |
11928 KB |
Output is correct |
17 |
Correct |
74 ms |
12184 KB |
Output is correct |
18 |
Correct |
48 ms |
12184 KB |
Output is correct |
19 |
Correct |
54 ms |
11928 KB |
Output is correct |
20 |
Correct |
62 ms |
12236 KB |
Output is correct |
21 |
Correct |
80 ms |
12060 KB |
Output is correct |
22 |
Correct |
90 ms |
11928 KB |
Output is correct |
23 |
Correct |
61 ms |
11928 KB |
Output is correct |
24 |
Correct |
75 ms |
12088 KB |
Output is correct |
25 |
Correct |
76 ms |
11928 KB |
Output is correct |
26 |
Correct |
48 ms |
11928 KB |
Output is correct |
27 |
Correct |
55 ms |
12060 KB |
Output is correct |
28 |
Correct |
53 ms |
11928 KB |
Output is correct |
29 |
Correct |
61 ms |
12056 KB |
Output is correct |
30 |
Correct |
62 ms |
11932 KB |
Output is correct |
31 |
Correct |
59 ms |
11928 KB |
Output is correct |
32 |
Correct |
102 ms |
12056 KB |
Output is correct |
33 |
Correct |
73 ms |
12056 KB |
Output is correct |
34 |
Correct |
49 ms |
11800 KB |
Output is correct |
35 |
Correct |
67 ms |
12056 KB |
Output is correct |
36 |
Correct |
69 ms |
12084 KB |
Output is correct |
37 |
Correct |
69 ms |
11928 KB |
Output is correct |
38 |
Correct |
67 ms |
12056 KB |
Output is correct |
39 |
Correct |
70 ms |
11928 KB |
Output is correct |
40 |
Correct |
85 ms |
11928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
314 ms |
15124 KB |
Output is correct |
12 |
Correct |
321 ms |
14944 KB |
Output is correct |
13 |
Correct |
298 ms |
14072 KB |
Output is correct |
14 |
Correct |
302 ms |
14200 KB |
Output is correct |
15 |
Correct |
386 ms |
15480 KB |
Output is correct |
16 |
Correct |
352 ms |
14408 KB |
Output is correct |
17 |
Correct |
341 ms |
14328 KB |
Output is correct |
18 |
Correct |
221 ms |
16120 KB |
Output is correct |
19 |
Correct |
254 ms |
13096 KB |
Output is correct |
20 |
Correct |
321 ms |
14840 KB |
Output is correct |
21 |
Correct |
300 ms |
18296 KB |
Output is correct |
22 |
Correct |
460 ms |
18376 KB |
Output is correct |
23 |
Correct |
378 ms |
17400 KB |
Output is correct |
24 |
Correct |
368 ms |
17144 KB |
Output is correct |
25 |
Correct |
384 ms |
19192 KB |
Output is correct |
26 |
Correct |
411 ms |
17656 KB |
Output is correct |
27 |
Correct |
408 ms |
17704 KB |
Output is correct |
28 |
Correct |
253 ms |
20216 KB |
Output is correct |
29 |
Correct |
282 ms |
16120 KB |
Output is correct |
30 |
Correct |
357 ms |
18552 KB |
Output is correct |
31 |
Correct |
464 ms |
18296 KB |
Output is correct |
32 |
Correct |
419 ms |
18296 KB |
Output is correct |
33 |
Correct |
330 ms |
17128 KB |
Output is correct |
34 |
Correct |
371 ms |
17272 KB |
Output is correct |
35 |
Correct |
408 ms |
17856 KB |
Output is correct |
36 |
Correct |
229 ms |
16120 KB |
Output is correct |
37 |
Correct |
412 ms |
18364 KB |
Output is correct |
38 |
Correct |
296 ms |
16248 KB |
Output is correct |
39 |
Correct |
385 ms |
17300 KB |
Output is correct |
40 |
Correct |
381 ms |
17144 KB |
Output is correct |
41 |
Correct |
61 ms |
12060 KB |
Output is correct |
42 |
Correct |
59 ms |
12060 KB |
Output is correct |
43 |
Correct |
68 ms |
11928 KB |
Output is correct |
44 |
Correct |
77 ms |
11928 KB |
Output is correct |
45 |
Correct |
62 ms |
12056 KB |
Output is correct |
46 |
Correct |
75 ms |
11928 KB |
Output is correct |
47 |
Correct |
74 ms |
12184 KB |
Output is correct |
48 |
Correct |
48 ms |
12184 KB |
Output is correct |
49 |
Correct |
54 ms |
11928 KB |
Output is correct |
50 |
Correct |
62 ms |
12236 KB |
Output is correct |
51 |
Correct |
80 ms |
12060 KB |
Output is correct |
52 |
Correct |
90 ms |
11928 KB |
Output is correct |
53 |
Correct |
61 ms |
11928 KB |
Output is correct |
54 |
Correct |
75 ms |
12088 KB |
Output is correct |
55 |
Correct |
76 ms |
11928 KB |
Output is correct |
56 |
Correct |
48 ms |
11928 KB |
Output is correct |
57 |
Correct |
55 ms |
12060 KB |
Output is correct |
58 |
Correct |
53 ms |
11928 KB |
Output is correct |
59 |
Correct |
61 ms |
12056 KB |
Output is correct |
60 |
Correct |
62 ms |
11932 KB |
Output is correct |
61 |
Correct |
59 ms |
11928 KB |
Output is correct |
62 |
Correct |
102 ms |
12056 KB |
Output is correct |
63 |
Correct |
73 ms |
12056 KB |
Output is correct |
64 |
Correct |
49 ms |
11800 KB |
Output is correct |
65 |
Correct |
67 ms |
12056 KB |
Output is correct |
66 |
Correct |
69 ms |
12084 KB |
Output is correct |
67 |
Correct |
69 ms |
11928 KB |
Output is correct |
68 |
Correct |
67 ms |
12056 KB |
Output is correct |
69 |
Correct |
70 ms |
11928 KB |
Output is correct |
70 |
Correct |
85 ms |
11928 KB |
Output is correct |
71 |
Correct |
452 ms |
36460 KB |
Output is correct |
72 |
Correct |
474 ms |
36504 KB |
Output is correct |
73 |
Correct |
530 ms |
35044 KB |
Output is correct |
74 |
Correct |
1006 ms |
35608 KB |
Output is correct |
75 |
Correct |
557 ms |
37356 KB |
Output is correct |
76 |
Correct |
1174 ms |
35848 KB |
Output is correct |
77 |
Correct |
802 ms |
35680 KB |
Output is correct |
78 |
Correct |
321 ms |
39320 KB |
Output is correct |
79 |
Correct |
383 ms |
33560 KB |
Output is correct |
80 |
Correct |
527 ms |
36508 KB |
Output is correct |
81 |
Correct |
692 ms |
36376 KB |
Output is correct |
82 |
Correct |
1402 ms |
35380 KB |
Output is correct |
83 |
Correct |
452 ms |
34584 KB |
Output is correct |
84 |
Correct |
599 ms |
35592 KB |
Output is correct |
85 |
Correct |
913 ms |
35536 KB |
Output is correct |
86 |
Correct |
289 ms |
33432 KB |
Output is correct |
87 |
Correct |
449 ms |
36500 KB |
Output is correct |
88 |
Correct |
385 ms |
33428 KB |
Output is correct |
89 |
Correct |
524 ms |
34972 KB |
Output is correct |
90 |
Correct |
608 ms |
35452 KB |
Output is correct |
91 |
Correct |
442 ms |
34528 KB |
Output is correct |
92 |
Correct |
954 ms |
35736 KB |
Output is correct |
93 |
Correct |
837 ms |
35608 KB |
Output is correct |
94 |
Correct |
294 ms |
33432 KB |
Output is correct |
95 |
Correct |
694 ms |
35436 KB |
Output is correct |
96 |
Correct |
681 ms |
35688 KB |
Output is correct |
97 |
Correct |
684 ms |
35580 KB |
Output is correct |
98 |
Correct |
859 ms |
35480 KB |
Output is correct |
99 |
Correct |
820 ms |
35476 KB |
Output is correct |
100 |
Correct |
766 ms |
35476 KB |
Output is correct |