#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen(".inp", "r"))
assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
using namespace chrono;
auto start = steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = steady_clock::now();
cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
int n, q, f0[1 << 20], f1[1 << 20], pc[1 << 20];
string s;
void Hollwo_Pelw(){
cin >> n >> q >> s;
for (int i = 0; i < 1 << n; i++) {
f0[i] = f1[i] = s[i] - '0';
}
for (int i = 0; i < 1 << n; i++)
pc[i] = __builtin_popcount(i);
for (int i = 0; i < n; i++) {
for (int mask = 0; mask < 1 << n; mask++) {
if (mask >> i & 1) {
f0[mask ^ 1 << i] += f0[mask];
f1[mask] += f1[mask ^ 1 << i];
}
}
}
for (string base; q --; ) {
cin >> base;
reverse(base.begin(), base.end());
int c0 = 0, c1 = 0, cq = 0;
for (int i = 0; i < n; i++) {
if (base[i] == '0') c0 |= 1 << i;
if (base[i] == '1') c1 |= 1 << i;
if (base[i] == '?') cq |= 1 << i;
}
if (pc[c0] <= 7) {
int res = 0;
for (int sub = c0; ; sub = (sub - 1) & c0) {
res += (pc[c0] % 2 == pc[sub] % 2 ? 1 : -1) * f0[c0 ^ c1 ^ sub];
if (!sub) break;
}
cout << res << '\n';
continue;
}
if (pc[c1] <= 7) {
int res = 0;
for (int sub = c1; ; sub = (sub - 1) & c1) {
res += (pc[c1] % 2 == pc[sub] % 2 ? 1 : -1) * f1[cq ^ sub];
if (!sub) break;
}
cout << res << '\n';
continue;
}
if (pc[cq] <= 7) {
int res = 0;
for (int sub = cq; ; sub = (sub - 1) & cq) {
res += s[sub | c1] - '0';
if (!sub) break;
}
cout << res << '\n';
continue;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
206 ms |
15040 KB |
Output is correct |
12 |
Correct |
290 ms |
14728 KB |
Output is correct |
13 |
Correct |
276 ms |
13936 KB |
Output is correct |
14 |
Correct |
248 ms |
13988 KB |
Output is correct |
15 |
Correct |
207 ms |
15068 KB |
Output is correct |
16 |
Correct |
225 ms |
14240 KB |
Output is correct |
17 |
Correct |
287 ms |
14192 KB |
Output is correct |
18 |
Correct |
165 ms |
16076 KB |
Output is correct |
19 |
Correct |
248 ms |
13044 KB |
Output is correct |
20 |
Correct |
226 ms |
14740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
206 ms |
15040 KB |
Output is correct |
12 |
Correct |
290 ms |
14728 KB |
Output is correct |
13 |
Correct |
276 ms |
13936 KB |
Output is correct |
14 |
Correct |
248 ms |
13988 KB |
Output is correct |
15 |
Correct |
207 ms |
15068 KB |
Output is correct |
16 |
Correct |
225 ms |
14240 KB |
Output is correct |
17 |
Correct |
287 ms |
14192 KB |
Output is correct |
18 |
Correct |
165 ms |
16076 KB |
Output is correct |
19 |
Correct |
248 ms |
13044 KB |
Output is correct |
20 |
Correct |
226 ms |
14740 KB |
Output is correct |
21 |
Correct |
216 ms |
18064 KB |
Output is correct |
22 |
Correct |
344 ms |
18260 KB |
Output is correct |
23 |
Correct |
371 ms |
17216 KB |
Output is correct |
24 |
Correct |
327 ms |
17064 KB |
Output is correct |
25 |
Correct |
246 ms |
19044 KB |
Output is correct |
26 |
Correct |
297 ms |
17636 KB |
Output is correct |
27 |
Correct |
388 ms |
17560 KB |
Output is correct |
28 |
Correct |
196 ms |
20244 KB |
Output is correct |
29 |
Correct |
373 ms |
16164 KB |
Output is correct |
30 |
Correct |
228 ms |
18280 KB |
Output is correct |
31 |
Correct |
277 ms |
18136 KB |
Output is correct |
32 |
Correct |
322 ms |
18104 KB |
Output is correct |
33 |
Correct |
240 ms |
16920 KB |
Output is correct |
34 |
Correct |
308 ms |
17072 KB |
Output is correct |
35 |
Correct |
334 ms |
17484 KB |
Output is correct |
36 |
Correct |
166 ms |
16076 KB |
Output is correct |
37 |
Correct |
472 ms |
18076 KB |
Output is correct |
38 |
Correct |
356 ms |
16044 KB |
Output is correct |
39 |
Correct |
293 ms |
17304 KB |
Output is correct |
40 |
Correct |
275 ms |
17084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
59 ms |
15992 KB |
Output is correct |
12 |
Correct |
53 ms |
16072 KB |
Output is correct |
13 |
Correct |
64 ms |
15940 KB |
Output is correct |
14 |
Correct |
93 ms |
15936 KB |
Output is correct |
15 |
Correct |
49 ms |
16112 KB |
Output is correct |
16 |
Correct |
63 ms |
15936 KB |
Output is correct |
17 |
Correct |
85 ms |
16008 KB |
Output is correct |
18 |
Correct |
45 ms |
16224 KB |
Output is correct |
19 |
Correct |
69 ms |
15920 KB |
Output is correct |
20 |
Correct |
50 ms |
16000 KB |
Output is correct |
21 |
Correct |
54 ms |
15972 KB |
Output is correct |
22 |
Correct |
64 ms |
15948 KB |
Output is correct |
23 |
Correct |
49 ms |
15964 KB |
Output is correct |
24 |
Correct |
74 ms |
15956 KB |
Output is correct |
25 |
Correct |
70 ms |
15948 KB |
Output is correct |
26 |
Correct |
39 ms |
15852 KB |
Output is correct |
27 |
Correct |
47 ms |
16064 KB |
Output is correct |
28 |
Correct |
53 ms |
15852 KB |
Output is correct |
29 |
Correct |
57 ms |
15980 KB |
Output is correct |
30 |
Correct |
103 ms |
15936 KB |
Output is correct |
31 |
Correct |
52 ms |
15940 KB |
Output is correct |
32 |
Correct |
73 ms |
15984 KB |
Output is correct |
33 |
Correct |
75 ms |
16084 KB |
Output is correct |
34 |
Correct |
42 ms |
15808 KB |
Output is correct |
35 |
Correct |
62 ms |
15948 KB |
Output is correct |
36 |
Correct |
60 ms |
15980 KB |
Output is correct |
37 |
Correct |
61 ms |
15936 KB |
Output is correct |
38 |
Correct |
65 ms |
15932 KB |
Output is correct |
39 |
Correct |
74 ms |
16000 KB |
Output is correct |
40 |
Correct |
65 ms |
16012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
206 ms |
15040 KB |
Output is correct |
12 |
Correct |
290 ms |
14728 KB |
Output is correct |
13 |
Correct |
276 ms |
13936 KB |
Output is correct |
14 |
Correct |
248 ms |
13988 KB |
Output is correct |
15 |
Correct |
207 ms |
15068 KB |
Output is correct |
16 |
Correct |
225 ms |
14240 KB |
Output is correct |
17 |
Correct |
287 ms |
14192 KB |
Output is correct |
18 |
Correct |
165 ms |
16076 KB |
Output is correct |
19 |
Correct |
248 ms |
13044 KB |
Output is correct |
20 |
Correct |
226 ms |
14740 KB |
Output is correct |
21 |
Correct |
216 ms |
18064 KB |
Output is correct |
22 |
Correct |
344 ms |
18260 KB |
Output is correct |
23 |
Correct |
371 ms |
17216 KB |
Output is correct |
24 |
Correct |
327 ms |
17064 KB |
Output is correct |
25 |
Correct |
246 ms |
19044 KB |
Output is correct |
26 |
Correct |
297 ms |
17636 KB |
Output is correct |
27 |
Correct |
388 ms |
17560 KB |
Output is correct |
28 |
Correct |
196 ms |
20244 KB |
Output is correct |
29 |
Correct |
373 ms |
16164 KB |
Output is correct |
30 |
Correct |
228 ms |
18280 KB |
Output is correct |
31 |
Correct |
277 ms |
18136 KB |
Output is correct |
32 |
Correct |
322 ms |
18104 KB |
Output is correct |
33 |
Correct |
240 ms |
16920 KB |
Output is correct |
34 |
Correct |
308 ms |
17072 KB |
Output is correct |
35 |
Correct |
334 ms |
17484 KB |
Output is correct |
36 |
Correct |
166 ms |
16076 KB |
Output is correct |
37 |
Correct |
472 ms |
18076 KB |
Output is correct |
38 |
Correct |
356 ms |
16044 KB |
Output is correct |
39 |
Correct |
293 ms |
17304 KB |
Output is correct |
40 |
Correct |
275 ms |
17084 KB |
Output is correct |
41 |
Correct |
59 ms |
15992 KB |
Output is correct |
42 |
Correct |
53 ms |
16072 KB |
Output is correct |
43 |
Correct |
64 ms |
15940 KB |
Output is correct |
44 |
Correct |
93 ms |
15936 KB |
Output is correct |
45 |
Correct |
49 ms |
16112 KB |
Output is correct |
46 |
Correct |
63 ms |
15936 KB |
Output is correct |
47 |
Correct |
85 ms |
16008 KB |
Output is correct |
48 |
Correct |
45 ms |
16224 KB |
Output is correct |
49 |
Correct |
69 ms |
15920 KB |
Output is correct |
50 |
Correct |
50 ms |
16000 KB |
Output is correct |
51 |
Correct |
54 ms |
15972 KB |
Output is correct |
52 |
Correct |
64 ms |
15948 KB |
Output is correct |
53 |
Correct |
49 ms |
15964 KB |
Output is correct |
54 |
Correct |
74 ms |
15956 KB |
Output is correct |
55 |
Correct |
70 ms |
15948 KB |
Output is correct |
56 |
Correct |
39 ms |
15852 KB |
Output is correct |
57 |
Correct |
47 ms |
16064 KB |
Output is correct |
58 |
Correct |
53 ms |
15852 KB |
Output is correct |
59 |
Correct |
57 ms |
15980 KB |
Output is correct |
60 |
Correct |
103 ms |
15936 KB |
Output is correct |
61 |
Correct |
52 ms |
15940 KB |
Output is correct |
62 |
Correct |
73 ms |
15984 KB |
Output is correct |
63 |
Correct |
75 ms |
16084 KB |
Output is correct |
64 |
Correct |
42 ms |
15808 KB |
Output is correct |
65 |
Correct |
62 ms |
15948 KB |
Output is correct |
66 |
Correct |
60 ms |
15980 KB |
Output is correct |
67 |
Correct |
61 ms |
15936 KB |
Output is correct |
68 |
Correct |
65 ms |
15932 KB |
Output is correct |
69 |
Correct |
74 ms |
16000 KB |
Output is correct |
70 |
Correct |
65 ms |
16012 KB |
Output is correct |
71 |
Correct |
308 ms |
21196 KB |
Output is correct |
72 |
Correct |
416 ms |
21228 KB |
Output is correct |
73 |
Correct |
547 ms |
19840 KB |
Output is correct |
74 |
Correct |
1061 ms |
20172 KB |
Output is correct |
75 |
Correct |
363 ms |
41216 KB |
Output is correct |
76 |
Correct |
705 ms |
39584 KB |
Output is correct |
77 |
Correct |
891 ms |
39396 KB |
Output is correct |
78 |
Correct |
228 ms |
43356 KB |
Output is correct |
79 |
Correct |
354 ms |
37280 KB |
Output is correct |
80 |
Correct |
343 ms |
40452 KB |
Output is correct |
81 |
Correct |
531 ms |
40268 KB |
Output is correct |
82 |
Correct |
701 ms |
39200 KB |
Output is correct |
83 |
Correct |
373 ms |
38428 KB |
Output is correct |
84 |
Correct |
858 ms |
39324 KB |
Output is correct |
85 |
Correct |
904 ms |
39492 KB |
Output is correct |
86 |
Correct |
213 ms |
37340 KB |
Output is correct |
87 |
Correct |
374 ms |
40252 KB |
Output is correct |
88 |
Correct |
502 ms |
37292 KB |
Output is correct |
89 |
Correct |
516 ms |
39016 KB |
Output is correct |
90 |
Correct |
1054 ms |
39404 KB |
Output is correct |
91 |
Correct |
411 ms |
38392 KB |
Output is correct |
92 |
Correct |
900 ms |
39556 KB |
Output is correct |
93 |
Correct |
864 ms |
39476 KB |
Output is correct |
94 |
Correct |
220 ms |
37236 KB |
Output is correct |
95 |
Correct |
679 ms |
39312 KB |
Output is correct |
96 |
Correct |
708 ms |
39316 KB |
Output is correct |
97 |
Correct |
673 ms |
39276 KB |
Output is correct |
98 |
Correct |
660 ms |
39368 KB |
Output is correct |
99 |
Correct |
695 ms |
39344 KB |
Output is correct |
100 |
Correct |
635 ms |
39264 KB |
Output is correct |