#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (1 << 20) + 12, MOD = (int)1e9 + 7;
int l, q, a[N], dp[N], pd[N];
void test() {
cin >> l >> q;
for(int i = 0; i < (1 << l); i++) {
char x;
cin >> x;
a[i] = (x - '0');
dp[i] = pd[i] = a[i];
}
for(int i = 0; i < l; i++) {
for(int j = 0; j < (1 << l); j++) {
if((j >> i) & 1) {
dp[j] += (dp[j - (1 << i)]);
}
}
for(int j = (1 << l) - 1; j >= 0; j--) {
if(!((j >> i) & 1)) {
pd[j] += pd[j + (1 << i)];
}
}
}
while(q--) {
vector<int> d, e, f;
int s = 0;
for(int i = l - 1; i >= 0; i--) {
char x;
cin >> x;
if(x == '0') {
d.push_back(i);
} else if(x == '1') {
s += (1 << i);
e.push_back(i);
} else {
f.push_back(i);
}
}
int res = 0, m;
if((int)f.size() <= 7 ) {
m = (int)f.size();
for(int i = 0; i < (1 << m); i++) {
int v = s;
for(int j = 0; j < m; j++) {
if((i >> j) & 1) {
v += (1 << f[j]);
}
}
res += a[v];
}
} else if((int)e.size() <= 7) {
m = (int)e.size();
for(int i:f) {
s += (1 << i);
}
res = 0;
for(int i = 0; i < (1 << m); i++) {
int v = s;
for(int j = 0; j < m; j++) {
if((i >> j) & 1) {
v -= (1 << e[j]);
}
}
if(__builtin_popcount(i) & 1) {
res -= dp[v];
} else {
res += dp[v];
}
}
} else {
m = (int)d.size();
for(int i = 0; i < (1 << m); i++) {
int v = s;
for(int j = 0; j < m; j++) {
if((i >> j) & 1) {
v += (1 << d[j]);
}
}
if(__builtin_popcount(i) & 1) {
res -= pd[v];
} else {
res += pd[v];
}
}
}
cout << res << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
479 ms |
19320 KB |
Output is correct |
12 |
Correct |
677 ms |
18808 KB |
Output is correct |
13 |
Correct |
429 ms |
18108 KB |
Output is correct |
14 |
Correct |
438 ms |
18248 KB |
Output is correct |
15 |
Correct |
723 ms |
19160 KB |
Output is correct |
16 |
Correct |
537 ms |
18444 KB |
Output is correct |
17 |
Correct |
515 ms |
18248 KB |
Output is correct |
18 |
Correct |
246 ms |
20296 KB |
Output is correct |
19 |
Correct |
345 ms |
17224 KB |
Output is correct |
20 |
Correct |
653 ms |
19012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
479 ms |
19320 KB |
Output is correct |
12 |
Correct |
677 ms |
18808 KB |
Output is correct |
13 |
Correct |
429 ms |
18108 KB |
Output is correct |
14 |
Correct |
438 ms |
18248 KB |
Output is correct |
15 |
Correct |
723 ms |
19160 KB |
Output is correct |
16 |
Correct |
537 ms |
18444 KB |
Output is correct |
17 |
Correct |
515 ms |
18248 KB |
Output is correct |
18 |
Correct |
246 ms |
20296 KB |
Output is correct |
19 |
Correct |
345 ms |
17224 KB |
Output is correct |
20 |
Correct |
653 ms |
19012 KB |
Output is correct |
21 |
Correct |
1437 ms |
22288 KB |
Output is correct |
22 |
Correct |
772 ms |
22260 KB |
Output is correct |
23 |
Correct |
629 ms |
21320 KB |
Output is correct |
24 |
Correct |
551 ms |
21124 KB |
Output is correct |
25 |
Correct |
462 ms |
23288 KB |
Output is correct |
26 |
Correct |
734 ms |
21608 KB |
Output is correct |
27 |
Correct |
720 ms |
21568 KB |
Output is correct |
28 |
Correct |
329 ms |
24136 KB |
Output is correct |
29 |
Correct |
413 ms |
20172 KB |
Output is correct |
30 |
Correct |
986 ms |
22376 KB |
Output is correct |
31 |
Correct |
788 ms |
22248 KB |
Output is correct |
32 |
Correct |
613 ms |
22088 KB |
Output is correct |
33 |
Correct |
453 ms |
21064 KB |
Output is correct |
34 |
Correct |
577 ms |
21172 KB |
Output is correct |
35 |
Correct |
734 ms |
21740 KB |
Output is correct |
36 |
Correct |
252 ms |
20296 KB |
Output is correct |
37 |
Correct |
719 ms |
22192 KB |
Output is correct |
38 |
Correct |
433 ms |
20296 KB |
Output is correct |
39 |
Correct |
579 ms |
21300 KB |
Output is correct |
40 |
Correct |
536 ms |
21320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
78 ms |
14920 KB |
Output is correct |
12 |
Correct |
79 ms |
15064 KB |
Output is correct |
13 |
Correct |
99 ms |
14804 KB |
Output is correct |
14 |
Correct |
138 ms |
14920 KB |
Output is correct |
15 |
Correct |
90 ms |
15124 KB |
Output is correct |
16 |
Correct |
112 ms |
14796 KB |
Output is correct |
17 |
Correct |
117 ms |
14920 KB |
Output is correct |
18 |
Correct |
69 ms |
15184 KB |
Output is correct |
19 |
Correct |
83 ms |
14932 KB |
Output is correct |
20 |
Correct |
106 ms |
15056 KB |
Output is correct |
21 |
Correct |
108 ms |
14936 KB |
Output is correct |
22 |
Correct |
145 ms |
14920 KB |
Output is correct |
23 |
Correct |
89 ms |
14796 KB |
Output is correct |
24 |
Correct |
112 ms |
14920 KB |
Output is correct |
25 |
Correct |
127 ms |
14840 KB |
Output is correct |
26 |
Correct |
64 ms |
14920 KB |
Output is correct |
27 |
Correct |
80 ms |
15064 KB |
Output is correct |
28 |
Correct |
87 ms |
14920 KB |
Output is correct |
29 |
Correct |
98 ms |
14988 KB |
Output is correct |
30 |
Correct |
112 ms |
14920 KB |
Output is correct |
31 |
Correct |
83 ms |
14792 KB |
Output is correct |
32 |
Correct |
110 ms |
14848 KB |
Output is correct |
33 |
Correct |
114 ms |
14920 KB |
Output is correct |
34 |
Correct |
64 ms |
14792 KB |
Output is correct |
35 |
Correct |
99 ms |
14792 KB |
Output is correct |
36 |
Correct |
104 ms |
14920 KB |
Output is correct |
37 |
Correct |
101 ms |
14972 KB |
Output is correct |
38 |
Correct |
99 ms |
14792 KB |
Output is correct |
39 |
Correct |
102 ms |
14920 KB |
Output is correct |
40 |
Correct |
107 ms |
14920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4432 KB |
Output is correct |
5 |
Correct |
2 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Correct |
2 ms |
4432 KB |
Output is correct |
8 |
Correct |
2 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
479 ms |
19320 KB |
Output is correct |
12 |
Correct |
677 ms |
18808 KB |
Output is correct |
13 |
Correct |
429 ms |
18108 KB |
Output is correct |
14 |
Correct |
438 ms |
18248 KB |
Output is correct |
15 |
Correct |
723 ms |
19160 KB |
Output is correct |
16 |
Correct |
537 ms |
18444 KB |
Output is correct |
17 |
Correct |
515 ms |
18248 KB |
Output is correct |
18 |
Correct |
246 ms |
20296 KB |
Output is correct |
19 |
Correct |
345 ms |
17224 KB |
Output is correct |
20 |
Correct |
653 ms |
19012 KB |
Output is correct |
21 |
Correct |
1437 ms |
22288 KB |
Output is correct |
22 |
Correct |
772 ms |
22260 KB |
Output is correct |
23 |
Correct |
629 ms |
21320 KB |
Output is correct |
24 |
Correct |
551 ms |
21124 KB |
Output is correct |
25 |
Correct |
462 ms |
23288 KB |
Output is correct |
26 |
Correct |
734 ms |
21608 KB |
Output is correct |
27 |
Correct |
720 ms |
21568 KB |
Output is correct |
28 |
Correct |
329 ms |
24136 KB |
Output is correct |
29 |
Correct |
413 ms |
20172 KB |
Output is correct |
30 |
Correct |
986 ms |
22376 KB |
Output is correct |
31 |
Correct |
788 ms |
22248 KB |
Output is correct |
32 |
Correct |
613 ms |
22088 KB |
Output is correct |
33 |
Correct |
453 ms |
21064 KB |
Output is correct |
34 |
Correct |
577 ms |
21172 KB |
Output is correct |
35 |
Correct |
734 ms |
21740 KB |
Output is correct |
36 |
Correct |
252 ms |
20296 KB |
Output is correct |
37 |
Correct |
719 ms |
22192 KB |
Output is correct |
38 |
Correct |
433 ms |
20296 KB |
Output is correct |
39 |
Correct |
579 ms |
21300 KB |
Output is correct |
40 |
Correct |
536 ms |
21320 KB |
Output is correct |
41 |
Correct |
78 ms |
14920 KB |
Output is correct |
42 |
Correct |
79 ms |
15064 KB |
Output is correct |
43 |
Correct |
99 ms |
14804 KB |
Output is correct |
44 |
Correct |
138 ms |
14920 KB |
Output is correct |
45 |
Correct |
90 ms |
15124 KB |
Output is correct |
46 |
Correct |
112 ms |
14796 KB |
Output is correct |
47 |
Correct |
117 ms |
14920 KB |
Output is correct |
48 |
Correct |
69 ms |
15184 KB |
Output is correct |
49 |
Correct |
83 ms |
14932 KB |
Output is correct |
50 |
Correct |
106 ms |
15056 KB |
Output is correct |
51 |
Correct |
108 ms |
14936 KB |
Output is correct |
52 |
Correct |
145 ms |
14920 KB |
Output is correct |
53 |
Correct |
89 ms |
14796 KB |
Output is correct |
54 |
Correct |
112 ms |
14920 KB |
Output is correct |
55 |
Correct |
127 ms |
14840 KB |
Output is correct |
56 |
Correct |
64 ms |
14920 KB |
Output is correct |
57 |
Correct |
80 ms |
15064 KB |
Output is correct |
58 |
Correct |
87 ms |
14920 KB |
Output is correct |
59 |
Correct |
98 ms |
14988 KB |
Output is correct |
60 |
Correct |
112 ms |
14920 KB |
Output is correct |
61 |
Correct |
83 ms |
14792 KB |
Output is correct |
62 |
Correct |
110 ms |
14848 KB |
Output is correct |
63 |
Correct |
114 ms |
14920 KB |
Output is correct |
64 |
Correct |
64 ms |
14792 KB |
Output is correct |
65 |
Correct |
99 ms |
14792 KB |
Output is correct |
66 |
Correct |
104 ms |
14920 KB |
Output is correct |
67 |
Correct |
101 ms |
14972 KB |
Output is correct |
68 |
Correct |
99 ms |
14792 KB |
Output is correct |
69 |
Correct |
102 ms |
14920 KB |
Output is correct |
70 |
Correct |
107 ms |
14920 KB |
Output is correct |
71 |
Correct |
655 ms |
39252 KB |
Output is correct |
72 |
Correct |
814 ms |
39496 KB |
Output is correct |
73 |
Correct |
1069 ms |
37892 KB |
Output is correct |
74 |
Correct |
1853 ms |
38220 KB |
Output is correct |
75 |
Correct |
802 ms |
40268 KB |
Output is correct |
76 |
Correct |
1336 ms |
38608 KB |
Output is correct |
77 |
Correct |
1413 ms |
38344 KB |
Output is correct |
78 |
Correct |
401 ms |
42312 KB |
Output is correct |
79 |
Correct |
695 ms |
36168 KB |
Output is correct |
80 |
Correct |
949 ms |
39496 KB |
Output is correct |
81 |
Correct |
1190 ms |
39152 KB |
Output is correct |
82 |
Correct |
1888 ms |
38336 KB |
Output is correct |
83 |
Correct |
823 ms |
37192 KB |
Output is correct |
84 |
Correct |
1235 ms |
38140 KB |
Output is correct |
85 |
Correct |
1572 ms |
38544 KB |
Output is correct |
86 |
Correct |
449 ms |
36168 KB |
Output is correct |
87 |
Correct |
735 ms |
39240 KB |
Output is correct |
88 |
Correct |
716 ms |
36168 KB |
Output is correct |
89 |
Correct |
1135 ms |
38012 KB |
Output is correct |
90 |
Correct |
1176 ms |
38192 KB |
Output is correct |
91 |
Correct |
832 ms |
37452 KB |
Output is correct |
92 |
Correct |
1567 ms |
38584 KB |
Output is correct |
93 |
Correct |
1449 ms |
38480 KB |
Output is correct |
94 |
Correct |
383 ms |
36168 KB |
Output is correct |
95 |
Correct |
1216 ms |
38216 KB |
Output is correct |
96 |
Correct |
1184 ms |
38408 KB |
Output is correct |
97 |
Correct |
1134 ms |
38216 KB |
Output is correct |
98 |
Correct |
1238 ms |
38396 KB |
Output is correct |
99 |
Correct |
1230 ms |
38412 KB |
Output is correct |
100 |
Correct |
1218 ms |
38216 KB |
Output is correct |