#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
int s1[(1 << Log) + 2];
int s0[(1 << Log) + 2];
int L, Q;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> L >> Q;
str s, t;
cin >> s;
t = s;
for(int i = 0; i < (1 << L); i++) s1[i] = s[i] - '0';
for(int i = 0; i < (1 << L); i++) s0[((1<<L) - 1) ^ i] = s[i] - '0';
for(int l = 0; l < L; l++)
for(int i = 0; i < (1 << L); i++)
if(i >> l & 1) s1[i ^ (1 << l)] += s1[i];
for(int l = 0; l < L; l++)
for(int i = 0; i < (1 << L); i++)
if(i >> l & 1) s0[i ^ (1 << l)] += s0[i];
while(Q --){
cin >> s;
int mk0 = 0, mk1 = 0, mkq = 0;
int c0 = 0, c1 = 0, cq = 0;
for(int i = 0; i < L; i++){
if(s[i] == '1') mk1 |= (1 << (L - 1 - i)), c1 ++;
if(s[i] == '0') mk0 |= (1 << (L - 1 - i)), c0 ++;
if(s[i] == '?') mkq |= (1 << (L - 1 - i)), cq ++;
}
if(cq <= min(c0, c1)){
int res = t[mk1]-'0';
int sub = mkq;
while(sub){
res += t[sub + mk1] - '0';
sub = mkq & (sub - 1);
}
cout << res << '\n';
continue;
}
if(c0 <= c1){
int res = s1[mk1];
int sub = mk0;
while(sub){
res += (__builtin_popcount(sub) & 1 ? -1 : 1) * s1[sub + mk1];
sub = mk0 & (sub - 1);
}
cout << res << '\n';
} else {
int res = s0[mk0];
int sub = mk1;
while(sub){
res += (__builtin_popcount(sub) & 1 ? -1 : 1) * s0[sub + mk0];
sub = mk1 & (sub - 1);
}
cout << res << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
384 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 |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
384 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 |
512 KB |
Output is correct |
11 |
Correct |
215 ms |
7036 KB |
Output is correct |
12 |
Correct |
232 ms |
6776 KB |
Output is correct |
13 |
Correct |
252 ms |
6064 KB |
Output is correct |
14 |
Correct |
247 ms |
6136 KB |
Output is correct |
15 |
Correct |
236 ms |
7124 KB |
Output is correct |
16 |
Correct |
274 ms |
6264 KB |
Output is correct |
17 |
Correct |
279 ms |
6264 KB |
Output is correct |
18 |
Correct |
180 ms |
8056 KB |
Output is correct |
19 |
Correct |
216 ms |
5116 KB |
Output is correct |
20 |
Correct |
239 ms |
6776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
384 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 |
512 KB |
Output is correct |
11 |
Correct |
215 ms |
7036 KB |
Output is correct |
12 |
Correct |
232 ms |
6776 KB |
Output is correct |
13 |
Correct |
252 ms |
6064 KB |
Output is correct |
14 |
Correct |
247 ms |
6136 KB |
Output is correct |
15 |
Correct |
236 ms |
7124 KB |
Output is correct |
16 |
Correct |
274 ms |
6264 KB |
Output is correct |
17 |
Correct |
279 ms |
6264 KB |
Output is correct |
18 |
Correct |
180 ms |
8056 KB |
Output is correct |
19 |
Correct |
216 ms |
5116 KB |
Output is correct |
20 |
Correct |
239 ms |
6776 KB |
Output is correct |
21 |
Correct |
247 ms |
7288 KB |
Output is correct |
22 |
Correct |
264 ms |
7320 KB |
Output is correct |
23 |
Correct |
301 ms |
6264 KB |
Output is correct |
24 |
Correct |
305 ms |
6136 KB |
Output is correct |
25 |
Correct |
271 ms |
8312 KB |
Output is correct |
26 |
Correct |
332 ms |
6648 KB |
Output is correct |
27 |
Correct |
327 ms |
6520 KB |
Output is correct |
28 |
Correct |
204 ms |
9208 KB |
Output is correct |
29 |
Correct |
243 ms |
5112 KB |
Output is correct |
30 |
Correct |
262 ms |
7416 KB |
Output is correct |
31 |
Correct |
305 ms |
7136 KB |
Output is correct |
32 |
Correct |
343 ms |
7160 KB |
Output is correct |
33 |
Correct |
281 ms |
6136 KB |
Output is correct |
34 |
Correct |
314 ms |
6264 KB |
Output is correct |
35 |
Correct |
322 ms |
6624 KB |
Output is correct |
36 |
Correct |
174 ms |
5116 KB |
Output is correct |
37 |
Correct |
244 ms |
7336 KB |
Output is correct |
38 |
Correct |
244 ms |
5240 KB |
Output is correct |
39 |
Correct |
305 ms |
6264 KB |
Output is correct |
40 |
Correct |
299 ms |
6216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
384 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 |
512 KB |
Output is correct |
11 |
Correct |
77 ms |
12312 KB |
Output is correct |
12 |
Correct |
78 ms |
12188 KB |
Output is correct |
13 |
Correct |
78 ms |
12056 KB |
Output is correct |
14 |
Correct |
99 ms |
12136 KB |
Output is correct |
15 |
Correct |
74 ms |
12188 KB |
Output is correct |
16 |
Correct |
102 ms |
12184 KB |
Output is correct |
17 |
Correct |
91 ms |
12184 KB |
Output is correct |
18 |
Correct |
69 ms |
12312 KB |
Output is correct |
19 |
Correct |
73 ms |
11940 KB |
Output is correct |
20 |
Correct |
76 ms |
12180 KB |
Output is correct |
21 |
Correct |
85 ms |
12184 KB |
Output is correct |
22 |
Correct |
109 ms |
11952 KB |
Output is correct |
23 |
Correct |
77 ms |
11928 KB |
Output is correct |
24 |
Correct |
86 ms |
11940 KB |
Output is correct |
25 |
Correct |
88 ms |
11932 KB |
Output is correct |
26 |
Correct |
68 ms |
11812 KB |
Output is correct |
27 |
Correct |
75 ms |
12060 KB |
Output is correct |
28 |
Correct |
74 ms |
11812 KB |
Output is correct |
29 |
Correct |
82 ms |
11928 KB |
Output is correct |
30 |
Correct |
81 ms |
11928 KB |
Output is correct |
31 |
Correct |
74 ms |
11928 KB |
Output is correct |
32 |
Correct |
96 ms |
11928 KB |
Output is correct |
33 |
Correct |
89 ms |
11932 KB |
Output is correct |
34 |
Correct |
66 ms |
11800 KB |
Output is correct |
35 |
Correct |
89 ms |
11928 KB |
Output is correct |
36 |
Correct |
83 ms |
11800 KB |
Output is correct |
37 |
Correct |
86 ms |
11800 KB |
Output is correct |
38 |
Correct |
85 ms |
11800 KB |
Output is correct |
39 |
Correct |
85 ms |
11800 KB |
Output is correct |
40 |
Correct |
83 ms |
11800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
384 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 |
512 KB |
Output is correct |
11 |
Correct |
215 ms |
7036 KB |
Output is correct |
12 |
Correct |
232 ms |
6776 KB |
Output is correct |
13 |
Correct |
252 ms |
6064 KB |
Output is correct |
14 |
Correct |
247 ms |
6136 KB |
Output is correct |
15 |
Correct |
236 ms |
7124 KB |
Output is correct |
16 |
Correct |
274 ms |
6264 KB |
Output is correct |
17 |
Correct |
279 ms |
6264 KB |
Output is correct |
18 |
Correct |
180 ms |
8056 KB |
Output is correct |
19 |
Correct |
216 ms |
5116 KB |
Output is correct |
20 |
Correct |
239 ms |
6776 KB |
Output is correct |
21 |
Correct |
247 ms |
7288 KB |
Output is correct |
22 |
Correct |
264 ms |
7320 KB |
Output is correct |
23 |
Correct |
301 ms |
6264 KB |
Output is correct |
24 |
Correct |
305 ms |
6136 KB |
Output is correct |
25 |
Correct |
271 ms |
8312 KB |
Output is correct |
26 |
Correct |
332 ms |
6648 KB |
Output is correct |
27 |
Correct |
327 ms |
6520 KB |
Output is correct |
28 |
Correct |
204 ms |
9208 KB |
Output is correct |
29 |
Correct |
243 ms |
5112 KB |
Output is correct |
30 |
Correct |
262 ms |
7416 KB |
Output is correct |
31 |
Correct |
305 ms |
7136 KB |
Output is correct |
32 |
Correct |
343 ms |
7160 KB |
Output is correct |
33 |
Correct |
281 ms |
6136 KB |
Output is correct |
34 |
Correct |
314 ms |
6264 KB |
Output is correct |
35 |
Correct |
322 ms |
6624 KB |
Output is correct |
36 |
Correct |
174 ms |
5116 KB |
Output is correct |
37 |
Correct |
244 ms |
7336 KB |
Output is correct |
38 |
Correct |
244 ms |
5240 KB |
Output is correct |
39 |
Correct |
305 ms |
6264 KB |
Output is correct |
40 |
Correct |
299 ms |
6216 KB |
Output is correct |
41 |
Correct |
77 ms |
12312 KB |
Output is correct |
42 |
Correct |
78 ms |
12188 KB |
Output is correct |
43 |
Correct |
78 ms |
12056 KB |
Output is correct |
44 |
Correct |
99 ms |
12136 KB |
Output is correct |
45 |
Correct |
74 ms |
12188 KB |
Output is correct |
46 |
Correct |
102 ms |
12184 KB |
Output is correct |
47 |
Correct |
91 ms |
12184 KB |
Output is correct |
48 |
Correct |
69 ms |
12312 KB |
Output is correct |
49 |
Correct |
73 ms |
11940 KB |
Output is correct |
50 |
Correct |
76 ms |
12180 KB |
Output is correct |
51 |
Correct |
85 ms |
12184 KB |
Output is correct |
52 |
Correct |
109 ms |
11952 KB |
Output is correct |
53 |
Correct |
77 ms |
11928 KB |
Output is correct |
54 |
Correct |
86 ms |
11940 KB |
Output is correct |
55 |
Correct |
88 ms |
11932 KB |
Output is correct |
56 |
Correct |
68 ms |
11812 KB |
Output is correct |
57 |
Correct |
75 ms |
12060 KB |
Output is correct |
58 |
Correct |
74 ms |
11812 KB |
Output is correct |
59 |
Correct |
82 ms |
11928 KB |
Output is correct |
60 |
Correct |
81 ms |
11928 KB |
Output is correct |
61 |
Correct |
74 ms |
11928 KB |
Output is correct |
62 |
Correct |
96 ms |
11928 KB |
Output is correct |
63 |
Correct |
89 ms |
11932 KB |
Output is correct |
64 |
Correct |
66 ms |
11800 KB |
Output is correct |
65 |
Correct |
89 ms |
11928 KB |
Output is correct |
66 |
Correct |
83 ms |
11800 KB |
Output is correct |
67 |
Correct |
86 ms |
11800 KB |
Output is correct |
68 |
Correct |
85 ms |
11800 KB |
Output is correct |
69 |
Correct |
85 ms |
11800 KB |
Output is correct |
70 |
Correct |
83 ms |
11800 KB |
Output is correct |
71 |
Correct |
385 ms |
16024 KB |
Output is correct |
72 |
Correct |
418 ms |
16152 KB |
Output is correct |
73 |
Correct |
450 ms |
14744 KB |
Output is correct |
74 |
Correct |
779 ms |
15128 KB |
Output is correct |
75 |
Correct |
403 ms |
17048 KB |
Output is correct |
76 |
Correct |
766 ms |
15384 KB |
Output is correct |
77 |
Correct |
707 ms |
15128 KB |
Output is correct |
78 |
Correct |
279 ms |
19096 KB |
Output is correct |
79 |
Correct |
360 ms |
14860 KB |
Output is correct |
80 |
Correct |
415 ms |
16024 KB |
Output is correct |
81 |
Correct |
538 ms |
16024 KB |
Output is correct |
82 |
Correct |
816 ms |
15128 KB |
Output is correct |
83 |
Correct |
400 ms |
14232 KB |
Output is correct |
84 |
Correct |
610 ms |
14872 KB |
Output is correct |
85 |
Correct |
704 ms |
15216 KB |
Output is correct |
86 |
Correct |
243 ms |
12952 KB |
Output is correct |
87 |
Correct |
406 ms |
15960 KB |
Output is correct |
88 |
Correct |
355 ms |
12824 KB |
Output is correct |
89 |
Correct |
495 ms |
14488 KB |
Output is correct |
90 |
Correct |
505 ms |
15128 KB |
Output is correct |
91 |
Correct |
383 ms |
14052 KB |
Output is correct |
92 |
Correct |
830 ms |
15248 KB |
Output is correct |
93 |
Correct |
676 ms |
15000 KB |
Output is correct |
94 |
Correct |
248 ms |
12824 KB |
Output is correct |
95 |
Correct |
579 ms |
15000 KB |
Output is correct |
96 |
Correct |
608 ms |
15000 KB |
Output is correct |
97 |
Correct |
604 ms |
15000 KB |
Output is correct |
98 |
Correct |
583 ms |
15008 KB |
Output is correct |
99 |
Correct |
590 ms |
15128 KB |
Output is correct |
100 |
Correct |
616 ms |
14936 KB |
Output is correct |