#include <bits/stdc++.h>
using namespace std;
const int nu = (1<<20);
int n, query, f[2][nu];
string s;
vector<int> cnt0, cnt1, cnt2;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> query >> s;
for(int i = 0; i < (1<<n); ++i) f[0][i] = f[1][i] = s[i]-48;
for(int i = 0; i < n; ++i)
for(int j = 0; j < (1<<n); ++j)
if((1<<i)&j) f[0][j] += f[0][j^(1<<i)];
else f[1][j] += f[1][j^(1<<i)];
while(query > 0)
{
string x;
cin >> x;
int num0 = 0; int num1 = 0; int num2 = 0; int ans = 0;
for(int i = 0; i < int(x.size()); ++i)
if(x[i] == '0') cnt0.push_back(n-i-1), num0 += (1<<(n-i-1)); else if(x[i] == '1') cnt1.push_back(n-i-1), num1 += (1<<(n-i-1));
else cnt2.push_back(n-i-1), num2 += (1<<(n-i-1));
if(int(cnt1.size()) <= n/3)
{
int len = int(cnt1.size());
for(int i = 0; i < (1<<len); ++i)
{
int num = 0; int d = 0;
for(int j = 0; j < len; ++j)
if((1<<j)&i) num += (1<<cnt1[j]), d++;
if(d&1) ans -= f[0][num|num2]; else ans += f[0][num|num2];
}
ans = abs(ans);
}
else if(int(cnt0.size()) <= n/3)
{
int len = int(cnt0.size());
for(int i = 0; i < (1<<len); ++i)
{
int num = 0; int d = 0;
for(int j = 0; j < len; ++j)
if((1<<j)&i) num += (1<<cnt0[j]), d++;
if(d&1) ans -= f[1][num|num1]; else ans += f[1][num|num1];
}
ans = abs(ans);
}
else
{
int len = int(cnt2.size());
for(int i = 0; i < (1<<len); ++i)
{
int num = 0; int d = 0;
for(int j = 0; j < len; ++j)
if((1<<j)&i) num += (1<<cnt2[j]), d++;
ans += s[num|num1]-48;
}
}
cout << ans << '\n';
cnt0.clear(); cnt1.clear(); cnt2.clear();
--query;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
332 KB |
Output is correct |
11 |
Correct |
208 ms |
15116 KB |
Output is correct |
12 |
Correct |
232 ms |
14756 KB |
Output is correct |
13 |
Correct |
253 ms |
13912 KB |
Output is correct |
14 |
Correct |
273 ms |
14092 KB |
Output is correct |
15 |
Correct |
256 ms |
15064 KB |
Output is correct |
16 |
Correct |
280 ms |
14284 KB |
Output is correct |
17 |
Correct |
284 ms |
14324 KB |
Output is correct |
18 |
Correct |
194 ms |
16108 KB |
Output is correct |
19 |
Correct |
203 ms |
13060 KB |
Output is correct |
20 |
Correct |
218 ms |
14768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
332 KB |
Output is correct |
11 |
Correct |
208 ms |
15116 KB |
Output is correct |
12 |
Correct |
232 ms |
14756 KB |
Output is correct |
13 |
Correct |
253 ms |
13912 KB |
Output is correct |
14 |
Correct |
273 ms |
14092 KB |
Output is correct |
15 |
Correct |
256 ms |
15064 KB |
Output is correct |
16 |
Correct |
280 ms |
14284 KB |
Output is correct |
17 |
Correct |
284 ms |
14324 KB |
Output is correct |
18 |
Correct |
194 ms |
16108 KB |
Output is correct |
19 |
Correct |
203 ms |
13060 KB |
Output is correct |
20 |
Correct |
218 ms |
14768 KB |
Output is correct |
21 |
Correct |
236 ms |
18136 KB |
Output is correct |
22 |
Correct |
278 ms |
18312 KB |
Output is correct |
23 |
Correct |
334 ms |
17340 KB |
Output is correct |
24 |
Correct |
387 ms |
17056 KB |
Output is correct |
25 |
Correct |
289 ms |
19132 KB |
Output is correct |
26 |
Correct |
369 ms |
17592 KB |
Output is correct |
27 |
Correct |
391 ms |
17504 KB |
Output is correct |
28 |
Correct |
199 ms |
20172 KB |
Output is correct |
29 |
Correct |
236 ms |
16188 KB |
Output is correct |
30 |
Correct |
291 ms |
18292 KB |
Output is correct |
31 |
Correct |
315 ms |
18116 KB |
Output is correct |
32 |
Correct |
361 ms |
18100 KB |
Output is correct |
33 |
Correct |
295 ms |
16948 KB |
Output is correct |
34 |
Correct |
380 ms |
17292 KB |
Output is correct |
35 |
Correct |
351 ms |
17668 KB |
Output is correct |
36 |
Correct |
188 ms |
16048 KB |
Output is correct |
37 |
Correct |
262 ms |
18080 KB |
Output is correct |
38 |
Correct |
307 ms |
16008 KB |
Output is correct |
39 |
Correct |
333 ms |
17372 KB |
Output is correct |
40 |
Correct |
350 ms |
17060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
332 KB |
Output is correct |
11 |
Correct |
49 ms |
11956 KB |
Output is correct |
12 |
Correct |
47 ms |
11868 KB |
Output is correct |
13 |
Correct |
66 ms |
11848 KB |
Output is correct |
14 |
Correct |
89 ms |
11936 KB |
Output is correct |
15 |
Correct |
49 ms |
12012 KB |
Output is correct |
16 |
Correct |
85 ms |
11844 KB |
Output is correct |
17 |
Correct |
78 ms |
11864 KB |
Output is correct |
18 |
Correct |
37 ms |
12092 KB |
Output is correct |
19 |
Correct |
42 ms |
11760 KB |
Output is correct |
20 |
Correct |
50 ms |
11940 KB |
Output is correct |
21 |
Correct |
63 ms |
11980 KB |
Output is correct |
22 |
Correct |
78 ms |
11872 KB |
Output is correct |
23 |
Correct |
50 ms |
11852 KB |
Output is correct |
24 |
Correct |
89 ms |
11840 KB |
Output is correct |
25 |
Correct |
83 ms |
11880 KB |
Output is correct |
26 |
Correct |
37 ms |
11756 KB |
Output is correct |
27 |
Correct |
44 ms |
11944 KB |
Output is correct |
28 |
Correct |
49 ms |
11708 KB |
Output is correct |
29 |
Correct |
61 ms |
11852 KB |
Output is correct |
30 |
Correct |
83 ms |
11848 KB |
Output is correct |
31 |
Correct |
51 ms |
11780 KB |
Output is correct |
32 |
Correct |
90 ms |
11848 KB |
Output is correct |
33 |
Correct |
95 ms |
11884 KB |
Output is correct |
34 |
Correct |
38 ms |
11708 KB |
Output is correct |
35 |
Correct |
63 ms |
11908 KB |
Output is correct |
36 |
Correct |
68 ms |
11820 KB |
Output is correct |
37 |
Correct |
67 ms |
11976 KB |
Output is correct |
38 |
Correct |
66 ms |
11852 KB |
Output is correct |
39 |
Correct |
67 ms |
11832 KB |
Output is correct |
40 |
Correct |
69 ms |
11848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
332 KB |
Output is correct |
11 |
Correct |
208 ms |
15116 KB |
Output is correct |
12 |
Correct |
232 ms |
14756 KB |
Output is correct |
13 |
Correct |
253 ms |
13912 KB |
Output is correct |
14 |
Correct |
273 ms |
14092 KB |
Output is correct |
15 |
Correct |
256 ms |
15064 KB |
Output is correct |
16 |
Correct |
280 ms |
14284 KB |
Output is correct |
17 |
Correct |
284 ms |
14324 KB |
Output is correct |
18 |
Correct |
194 ms |
16108 KB |
Output is correct |
19 |
Correct |
203 ms |
13060 KB |
Output is correct |
20 |
Correct |
218 ms |
14768 KB |
Output is correct |
21 |
Correct |
236 ms |
18136 KB |
Output is correct |
22 |
Correct |
278 ms |
18312 KB |
Output is correct |
23 |
Correct |
334 ms |
17340 KB |
Output is correct |
24 |
Correct |
387 ms |
17056 KB |
Output is correct |
25 |
Correct |
289 ms |
19132 KB |
Output is correct |
26 |
Correct |
369 ms |
17592 KB |
Output is correct |
27 |
Correct |
391 ms |
17504 KB |
Output is correct |
28 |
Correct |
199 ms |
20172 KB |
Output is correct |
29 |
Correct |
236 ms |
16188 KB |
Output is correct |
30 |
Correct |
291 ms |
18292 KB |
Output is correct |
31 |
Correct |
315 ms |
18116 KB |
Output is correct |
32 |
Correct |
361 ms |
18100 KB |
Output is correct |
33 |
Correct |
295 ms |
16948 KB |
Output is correct |
34 |
Correct |
380 ms |
17292 KB |
Output is correct |
35 |
Correct |
351 ms |
17668 KB |
Output is correct |
36 |
Correct |
188 ms |
16048 KB |
Output is correct |
37 |
Correct |
262 ms |
18080 KB |
Output is correct |
38 |
Correct |
307 ms |
16008 KB |
Output is correct |
39 |
Correct |
333 ms |
17372 KB |
Output is correct |
40 |
Correct |
350 ms |
17060 KB |
Output is correct |
41 |
Correct |
49 ms |
11956 KB |
Output is correct |
42 |
Correct |
47 ms |
11868 KB |
Output is correct |
43 |
Correct |
66 ms |
11848 KB |
Output is correct |
44 |
Correct |
89 ms |
11936 KB |
Output is correct |
45 |
Correct |
49 ms |
12012 KB |
Output is correct |
46 |
Correct |
85 ms |
11844 KB |
Output is correct |
47 |
Correct |
78 ms |
11864 KB |
Output is correct |
48 |
Correct |
37 ms |
12092 KB |
Output is correct |
49 |
Correct |
42 ms |
11760 KB |
Output is correct |
50 |
Correct |
50 ms |
11940 KB |
Output is correct |
51 |
Correct |
63 ms |
11980 KB |
Output is correct |
52 |
Correct |
78 ms |
11872 KB |
Output is correct |
53 |
Correct |
50 ms |
11852 KB |
Output is correct |
54 |
Correct |
89 ms |
11840 KB |
Output is correct |
55 |
Correct |
83 ms |
11880 KB |
Output is correct |
56 |
Correct |
37 ms |
11756 KB |
Output is correct |
57 |
Correct |
44 ms |
11944 KB |
Output is correct |
58 |
Correct |
49 ms |
11708 KB |
Output is correct |
59 |
Correct |
61 ms |
11852 KB |
Output is correct |
60 |
Correct |
83 ms |
11848 KB |
Output is correct |
61 |
Correct |
51 ms |
11780 KB |
Output is correct |
62 |
Correct |
90 ms |
11848 KB |
Output is correct |
63 |
Correct |
95 ms |
11884 KB |
Output is correct |
64 |
Correct |
38 ms |
11708 KB |
Output is correct |
65 |
Correct |
63 ms |
11908 KB |
Output is correct |
66 |
Correct |
68 ms |
11820 KB |
Output is correct |
67 |
Correct |
67 ms |
11976 KB |
Output is correct |
68 |
Correct |
66 ms |
11852 KB |
Output is correct |
69 |
Correct |
67 ms |
11832 KB |
Output is correct |
70 |
Correct |
69 ms |
11848 KB |
Output is correct |
71 |
Correct |
414 ms |
36140 KB |
Output is correct |
72 |
Correct |
424 ms |
36344 KB |
Output is correct |
73 |
Correct |
681 ms |
34836 KB |
Output is correct |
74 |
Correct |
1217 ms |
35328 KB |
Output is correct |
75 |
Correct |
532 ms |
37228 KB |
Output is correct |
76 |
Correct |
1316 ms |
35588 KB |
Output is correct |
77 |
Correct |
1038 ms |
35588 KB |
Output is correct |
78 |
Correct |
291 ms |
39192 KB |
Output is correct |
79 |
Correct |
351 ms |
33260 KB |
Output is correct |
80 |
Correct |
441 ms |
36424 KB |
Output is correct |
81 |
Correct |
675 ms |
36220 KB |
Output is correct |
82 |
Correct |
1471 ms |
35268 KB |
Output is correct |
83 |
Correct |
516 ms |
34328 KB |
Output is correct |
84 |
Correct |
1126 ms |
35204 KB |
Output is correct |
85 |
Correct |
1022 ms |
35416 KB |
Output is correct |
86 |
Correct |
263 ms |
33120 KB |
Output is correct |
87 |
Correct |
422 ms |
36204 KB |
Output is correct |
88 |
Correct |
436 ms |
33208 KB |
Output is correct |
89 |
Correct |
695 ms |
34984 KB |
Output is correct |
90 |
Correct |
1016 ms |
35412 KB |
Output is correct |
91 |
Correct |
554 ms |
34464 KB |
Output is correct |
92 |
Correct |
1116 ms |
35592 KB |
Output is correct |
93 |
Correct |
1002 ms |
35428 KB |
Output is correct |
94 |
Correct |
263 ms |
33200 KB |
Output is correct |
95 |
Correct |
806 ms |
35236 KB |
Output is correct |
96 |
Correct |
804 ms |
35364 KB |
Output is correct |
97 |
Correct |
851 ms |
35564 KB |
Output is correct |
98 |
Correct |
866 ms |
35216 KB |
Output is correct |
99 |
Correct |
890 ms |
35344 KB |
Output is correct |
100 |
Correct |
828 ms |
35336 KB |
Output is correct |