#include <bits/stdc++.h>
#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;
for(int i = 0; i < L; i++){
if(s[i] == '1') mk1 |= (1 << (L - 1 - i));
if(s[i] == '0') mk0 |= (1 << (L - 1 - i));
if(s[i] == '?') mkq |= (1 << (L - 1 - i));
}
if(__builtin_popcount(mkq) < 7){
int res = t[mk1]-'0';
int sub = mkq;
while(sub){
res += t[sub + mk1] - '0';
sub = mkq & (sub - 1);
}
cout << res << '\n';
continue;
}
if(__builtin_popcount(mk0) < __builtin_popcount(mk1)){
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
404 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 |
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 |
404 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 |
384 KB |
Output is correct |
11 |
Correct |
262 ms |
5880 KB |
Output is correct |
12 |
Correct |
284 ms |
5496 KB |
Output is correct |
13 |
Correct |
264 ms |
4820 KB |
Output is correct |
14 |
Correct |
257 ms |
5016 KB |
Output is correct |
15 |
Correct |
315 ms |
5884 KB |
Output is correct |
16 |
Correct |
282 ms |
5072 KB |
Output is correct |
17 |
Correct |
283 ms |
4984 KB |
Output is correct |
18 |
Correct |
201 ms |
6904 KB |
Output is correct |
19 |
Correct |
224 ms |
3960 KB |
Output is correct |
20 |
Correct |
283 ms |
5496 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 |
404 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 |
384 KB |
Output is correct |
11 |
Correct |
262 ms |
5880 KB |
Output is correct |
12 |
Correct |
284 ms |
5496 KB |
Output is correct |
13 |
Correct |
264 ms |
4820 KB |
Output is correct |
14 |
Correct |
257 ms |
5016 KB |
Output is correct |
15 |
Correct |
315 ms |
5884 KB |
Output is correct |
16 |
Correct |
282 ms |
5072 KB |
Output is correct |
17 |
Correct |
283 ms |
4984 KB |
Output is correct |
18 |
Correct |
201 ms |
6904 KB |
Output is correct |
19 |
Correct |
224 ms |
3960 KB |
Output is correct |
20 |
Correct |
283 ms |
5496 KB |
Output is correct |
21 |
Correct |
268 ms |
5996 KB |
Output is correct |
22 |
Correct |
310 ms |
6264 KB |
Output is correct |
23 |
Correct |
315 ms |
5112 KB |
Output is correct |
24 |
Correct |
301 ms |
4984 KB |
Output is correct |
25 |
Correct |
290 ms |
6904 KB |
Output is correct |
26 |
Correct |
340 ms |
5548 KB |
Output is correct |
27 |
Correct |
332 ms |
5368 KB |
Output is correct |
28 |
Correct |
222 ms |
7928 KB |
Output is correct |
29 |
Correct |
249 ms |
4088 KB |
Output is correct |
30 |
Correct |
311 ms |
6008 KB |
Output is correct |
31 |
Correct |
364 ms |
5952 KB |
Output is correct |
32 |
Correct |
327 ms |
5752 KB |
Output is correct |
33 |
Correct |
289 ms |
4728 KB |
Output is correct |
34 |
Correct |
301 ms |
4836 KB |
Output is correct |
35 |
Correct |
335 ms |
5240 KB |
Output is correct |
36 |
Correct |
188 ms |
3704 KB |
Output is correct |
37 |
Correct |
341 ms |
5880 KB |
Output is correct |
38 |
Correct |
258 ms |
3520 KB |
Output is correct |
39 |
Correct |
318 ms |
4728 KB |
Output is correct |
40 |
Correct |
302 ms |
4600 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 |
404 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 |
384 KB |
Output is correct |
11 |
Correct |
76 ms |
12056 KB |
Output is correct |
12 |
Correct |
75 ms |
12084 KB |
Output is correct |
13 |
Correct |
80 ms |
11936 KB |
Output is correct |
14 |
Correct |
97 ms |
11928 KB |
Output is correct |
15 |
Correct |
76 ms |
12184 KB |
Output is correct |
16 |
Correct |
99 ms |
11932 KB |
Output is correct |
17 |
Correct |
93 ms |
12056 KB |
Output is correct |
18 |
Correct |
71 ms |
12184 KB |
Output is correct |
19 |
Correct |
78 ms |
11924 KB |
Output is correct |
20 |
Correct |
80 ms |
12056 KB |
Output is correct |
21 |
Correct |
87 ms |
12056 KB |
Output is correct |
22 |
Correct |
101 ms |
11928 KB |
Output is correct |
23 |
Correct |
79 ms |
11928 KB |
Output is correct |
24 |
Correct |
80 ms |
11928 KB |
Output is correct |
25 |
Correct |
91 ms |
11928 KB |
Output is correct |
26 |
Correct |
68 ms |
11928 KB |
Output is correct |
27 |
Correct |
76 ms |
12056 KB |
Output is correct |
28 |
Correct |
75 ms |
11928 KB |
Output is correct |
29 |
Correct |
80 ms |
11932 KB |
Output is correct |
30 |
Correct |
79 ms |
11928 KB |
Output is correct |
31 |
Correct |
78 ms |
11928 KB |
Output is correct |
32 |
Correct |
107 ms |
11928 KB |
Output is correct |
33 |
Correct |
94 ms |
11800 KB |
Output is correct |
34 |
Correct |
70 ms |
12568 KB |
Output is correct |
35 |
Correct |
88 ms |
11800 KB |
Output is correct |
36 |
Correct |
88 ms |
12024 KB |
Output is correct |
37 |
Correct |
89 ms |
11804 KB |
Output is correct |
38 |
Correct |
94 ms |
11800 KB |
Output is correct |
39 |
Correct |
88 ms |
11800 KB |
Output is correct |
40 |
Correct |
84 ms |
11804 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 |
404 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 |
384 KB |
Output is correct |
11 |
Correct |
262 ms |
5880 KB |
Output is correct |
12 |
Correct |
284 ms |
5496 KB |
Output is correct |
13 |
Correct |
264 ms |
4820 KB |
Output is correct |
14 |
Correct |
257 ms |
5016 KB |
Output is correct |
15 |
Correct |
315 ms |
5884 KB |
Output is correct |
16 |
Correct |
282 ms |
5072 KB |
Output is correct |
17 |
Correct |
283 ms |
4984 KB |
Output is correct |
18 |
Correct |
201 ms |
6904 KB |
Output is correct |
19 |
Correct |
224 ms |
3960 KB |
Output is correct |
20 |
Correct |
283 ms |
5496 KB |
Output is correct |
21 |
Correct |
268 ms |
5996 KB |
Output is correct |
22 |
Correct |
310 ms |
6264 KB |
Output is correct |
23 |
Correct |
315 ms |
5112 KB |
Output is correct |
24 |
Correct |
301 ms |
4984 KB |
Output is correct |
25 |
Correct |
290 ms |
6904 KB |
Output is correct |
26 |
Correct |
340 ms |
5548 KB |
Output is correct |
27 |
Correct |
332 ms |
5368 KB |
Output is correct |
28 |
Correct |
222 ms |
7928 KB |
Output is correct |
29 |
Correct |
249 ms |
4088 KB |
Output is correct |
30 |
Correct |
311 ms |
6008 KB |
Output is correct |
31 |
Correct |
364 ms |
5952 KB |
Output is correct |
32 |
Correct |
327 ms |
5752 KB |
Output is correct |
33 |
Correct |
289 ms |
4728 KB |
Output is correct |
34 |
Correct |
301 ms |
4836 KB |
Output is correct |
35 |
Correct |
335 ms |
5240 KB |
Output is correct |
36 |
Correct |
188 ms |
3704 KB |
Output is correct |
37 |
Correct |
341 ms |
5880 KB |
Output is correct |
38 |
Correct |
258 ms |
3520 KB |
Output is correct |
39 |
Correct |
318 ms |
4728 KB |
Output is correct |
40 |
Correct |
302 ms |
4600 KB |
Output is correct |
41 |
Correct |
76 ms |
12056 KB |
Output is correct |
42 |
Correct |
75 ms |
12084 KB |
Output is correct |
43 |
Correct |
80 ms |
11936 KB |
Output is correct |
44 |
Correct |
97 ms |
11928 KB |
Output is correct |
45 |
Correct |
76 ms |
12184 KB |
Output is correct |
46 |
Correct |
99 ms |
11932 KB |
Output is correct |
47 |
Correct |
93 ms |
12056 KB |
Output is correct |
48 |
Correct |
71 ms |
12184 KB |
Output is correct |
49 |
Correct |
78 ms |
11924 KB |
Output is correct |
50 |
Correct |
80 ms |
12056 KB |
Output is correct |
51 |
Correct |
87 ms |
12056 KB |
Output is correct |
52 |
Correct |
101 ms |
11928 KB |
Output is correct |
53 |
Correct |
79 ms |
11928 KB |
Output is correct |
54 |
Correct |
80 ms |
11928 KB |
Output is correct |
55 |
Correct |
91 ms |
11928 KB |
Output is correct |
56 |
Correct |
68 ms |
11928 KB |
Output is correct |
57 |
Correct |
76 ms |
12056 KB |
Output is correct |
58 |
Correct |
75 ms |
11928 KB |
Output is correct |
59 |
Correct |
80 ms |
11932 KB |
Output is correct |
60 |
Correct |
79 ms |
11928 KB |
Output is correct |
61 |
Correct |
78 ms |
11928 KB |
Output is correct |
62 |
Correct |
107 ms |
11928 KB |
Output is correct |
63 |
Correct |
94 ms |
11800 KB |
Output is correct |
64 |
Correct |
70 ms |
12568 KB |
Output is correct |
65 |
Correct |
88 ms |
11800 KB |
Output is correct |
66 |
Correct |
88 ms |
12024 KB |
Output is correct |
67 |
Correct |
89 ms |
11804 KB |
Output is correct |
68 |
Correct |
94 ms |
11800 KB |
Output is correct |
69 |
Correct |
88 ms |
11800 KB |
Output is correct |
70 |
Correct |
84 ms |
11804 KB |
Output is correct |
71 |
Correct |
442 ms |
15768 KB |
Output is correct |
72 |
Correct |
439 ms |
16108 KB |
Output is correct |
73 |
Correct |
465 ms |
14488 KB |
Output is correct |
74 |
Correct |
774 ms |
14872 KB |
Output is correct |
75 |
Correct |
423 ms |
16792 KB |
Output is correct |
76 |
Correct |
910 ms |
15228 KB |
Output is correct |
77 |
Correct |
738 ms |
15192 KB |
Output is correct |
78 |
Correct |
302 ms |
18840 KB |
Output is correct |
79 |
Correct |
369 ms |
24600 KB |
Output is correct |
80 |
Correct |
461 ms |
37440 KB |
Output is correct |
81 |
Correct |
625 ms |
37400 KB |
Output is correct |
82 |
Correct |
769 ms |
36504 KB |
Output is correct |
83 |
Correct |
420 ms |
35604 KB |
Output is correct |
84 |
Correct |
529 ms |
36420 KB |
Output is correct |
85 |
Correct |
739 ms |
36760 KB |
Output is correct |
86 |
Correct |
259 ms |
34324 KB |
Output is correct |
87 |
Correct |
414 ms |
37400 KB |
Output is correct |
88 |
Correct |
388 ms |
34468 KB |
Output is correct |
89 |
Correct |
512 ms |
36116 KB |
Output is correct |
90 |
Correct |
533 ms |
36360 KB |
Output is correct |
91 |
Correct |
391 ms |
35608 KB |
Output is correct |
92 |
Correct |
814 ms |
36768 KB |
Output is correct |
93 |
Correct |
758 ms |
36912 KB |
Output is correct |
94 |
Correct |
283 ms |
34452 KB |
Output is correct |
95 |
Correct |
631 ms |
36504 KB |
Output is correct |
96 |
Correct |
675 ms |
36500 KB |
Output is correct |
97 |
Correct |
642 ms |
36632 KB |
Output is correct |
98 |
Correct |
676 ms |
36376 KB |
Output is correct |
99 |
Correct |
637 ms |
36504 KB |
Output is correct |
100 |
Correct |
649 ms |
36520 KB |
Output is correct |