// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << endl, exit(0);
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)(1<<21) + 7;
const int MOD = 998244353;
const int INF = (int)1e18 + 7;
const int LG = 21;
int n, m, t, flag, u, v, w, k, tmp, tmp2, tmp3, tmp4, tmp5, tmp6, ans, q, h;
int arr[MAXN], sub[MAXN], sup[MAXN];
string s, s2;
int Z, O, Q;
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
cin >> s;
for (int i=0; i<(1<<n); i++) sub[i] = sup[i] = s[i]-'0';
for (int j=0; j<LG; j++) for (int i=0; i<MAXN; i++) if (i&(1<<j)) sub[i] += sub[i^(1<<j)];
for (int j=0; j<LG; j++) for (int i=MAXN-1; i>=0; i--) if (i&(1<<j)) sup[i^(1<<j)] += sup[i];
while (q--) {
cin >> s2;
reverse(all(s2));
Z = O = Q = 0;
for (int i=0; i<n; i++) {
if (s2[i] == '1') {
O += (1<<i);
} else if (s2[i] == '0') {
Z += (1<<i);
} else {
Q += (1<<i);
}
}
if (__builtin_popcount(Q) <= 10 ) {
ans = s[O]-'0';
for (int mask=Q; mask!=0; mask=Q&(mask-1)) ans += s[mask+O]-'0';
} else if (__builtin_popcount(Z) <= 10) {
ans = sup[O];
for (int mask=Z; mask!=0; mask=Z&(mask-1)) ans += sup[mask+O]*((__builtin_popcount(mask)%2) == 1? -1 : 1);
} else {
// ans = (s[Q]-'0')*(__builtin_popcount(O)%2 == 1? -1 : 1);
// for (int mask=O; mask!=0; mask=O&(mask-1)) ans += sub[mask+Q]*(__builtin_popcount(O-mask)%2 == 1? -1 : 1);
}
cout << ans << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
33108 KB |
Output is correct |
2 |
Correct |
82 ms |
33108 KB |
Output is correct |
3 |
Correct |
95 ms |
33104 KB |
Output is correct |
4 |
Correct |
80 ms |
33104 KB |
Output is correct |
5 |
Correct |
77 ms |
33204 KB |
Output is correct |
6 |
Correct |
79 ms |
33108 KB |
Output is correct |
7 |
Correct |
79 ms |
33100 KB |
Output is correct |
8 |
Correct |
79 ms |
33284 KB |
Output is correct |
9 |
Correct |
88 ms |
33108 KB |
Output is correct |
10 |
Correct |
81 ms |
33104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
33108 KB |
Output is correct |
2 |
Correct |
82 ms |
33108 KB |
Output is correct |
3 |
Correct |
95 ms |
33104 KB |
Output is correct |
4 |
Correct |
80 ms |
33104 KB |
Output is correct |
5 |
Correct |
77 ms |
33204 KB |
Output is correct |
6 |
Correct |
79 ms |
33108 KB |
Output is correct |
7 |
Correct |
79 ms |
33100 KB |
Output is correct |
8 |
Correct |
79 ms |
33284 KB |
Output is correct |
9 |
Correct |
88 ms |
33108 KB |
Output is correct |
10 |
Correct |
81 ms |
33104 KB |
Output is correct |
11 |
Correct |
267 ms |
47956 KB |
Output is correct |
12 |
Correct |
314 ms |
47700 KB |
Output is correct |
13 |
Correct |
267 ms |
46924 KB |
Output is correct |
14 |
Correct |
263 ms |
46932 KB |
Output is correct |
15 |
Correct |
317 ms |
47948 KB |
Output is correct |
16 |
Correct |
289 ms |
47180 KB |
Output is correct |
17 |
Correct |
295 ms |
47360 KB |
Output is correct |
18 |
Correct |
1266 ms |
49168 KB |
Output is correct |
19 |
Correct |
235 ms |
45908 KB |
Output is correct |
20 |
Correct |
305 ms |
47704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
33108 KB |
Output is correct |
2 |
Correct |
82 ms |
33108 KB |
Output is correct |
3 |
Correct |
95 ms |
33104 KB |
Output is correct |
4 |
Correct |
80 ms |
33104 KB |
Output is correct |
5 |
Correct |
77 ms |
33204 KB |
Output is correct |
6 |
Correct |
79 ms |
33108 KB |
Output is correct |
7 |
Correct |
79 ms |
33100 KB |
Output is correct |
8 |
Correct |
79 ms |
33284 KB |
Output is correct |
9 |
Correct |
88 ms |
33108 KB |
Output is correct |
10 |
Correct |
81 ms |
33104 KB |
Output is correct |
11 |
Correct |
267 ms |
47956 KB |
Output is correct |
12 |
Correct |
314 ms |
47700 KB |
Output is correct |
13 |
Correct |
267 ms |
46924 KB |
Output is correct |
14 |
Correct |
263 ms |
46932 KB |
Output is correct |
15 |
Correct |
317 ms |
47948 KB |
Output is correct |
16 |
Correct |
289 ms |
47180 KB |
Output is correct |
17 |
Correct |
295 ms |
47360 KB |
Output is correct |
18 |
Correct |
1266 ms |
49168 KB |
Output is correct |
19 |
Correct |
235 ms |
45908 KB |
Output is correct |
20 |
Correct |
305 ms |
47704 KB |
Output is correct |
21 |
Correct |
398 ms |
51028 KB |
Output is correct |
22 |
Correct |
450 ms |
51152 KB |
Output is correct |
23 |
Correct |
299 ms |
50000 KB |
Output is correct |
24 |
Correct |
298 ms |
50004 KB |
Output is correct |
25 |
Correct |
534 ms |
52096 KB |
Output is correct |
26 |
Correct |
335 ms |
50508 KB |
Output is correct |
27 |
Correct |
341 ms |
50436 KB |
Output is correct |
28 |
Correct |
223 ms |
53308 KB |
Output is correct |
29 |
Correct |
267 ms |
48980 KB |
Output is correct |
30 |
Correct |
465 ms |
51284 KB |
Output is correct |
31 |
Correct |
353 ms |
50880 KB |
Output is correct |
32 |
Correct |
348 ms |
50772 KB |
Output is correct |
33 |
Correct |
290 ms |
50136 KB |
Output is correct |
34 |
Correct |
306 ms |
49840 KB |
Output is correct |
35 |
Correct |
367 ms |
50268 KB |
Output is correct |
36 |
Correct |
218 ms |
48976 KB |
Output is correct |
37 |
Correct |
337 ms |
51004 KB |
Output is correct |
38 |
Correct |
286 ms |
49236 KB |
Output is correct |
39 |
Correct |
319 ms |
50040 KB |
Output is correct |
40 |
Correct |
297 ms |
50004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
33108 KB |
Output is correct |
2 |
Correct |
82 ms |
33108 KB |
Output is correct |
3 |
Correct |
95 ms |
33104 KB |
Output is correct |
4 |
Correct |
80 ms |
33104 KB |
Output is correct |
5 |
Correct |
77 ms |
33204 KB |
Output is correct |
6 |
Correct |
79 ms |
33108 KB |
Output is correct |
7 |
Correct |
79 ms |
33100 KB |
Output is correct |
8 |
Correct |
79 ms |
33284 KB |
Output is correct |
9 |
Correct |
88 ms |
33108 KB |
Output is correct |
10 |
Correct |
81 ms |
33104 KB |
Output is correct |
11 |
Correct |
155 ms |
36596 KB |
Output is correct |
12 |
Correct |
128 ms |
36628 KB |
Output is correct |
13 |
Correct |
96 ms |
36468 KB |
Output is correct |
14 |
Correct |
105 ms |
36592 KB |
Output is correct |
15 |
Correct |
91 ms |
36596 KB |
Output is correct |
16 |
Correct |
110 ms |
36592 KB |
Output is correct |
17 |
Correct |
115 ms |
36480 KB |
Output is correct |
18 |
Correct |
88 ms |
36728 KB |
Output is correct |
19 |
Correct |
92 ms |
36344 KB |
Output is correct |
20 |
Correct |
110 ms |
36724 KB |
Output is correct |
21 |
Correct |
172 ms |
36724 KB |
Output is correct |
22 |
Correct |
104 ms |
36596 KB |
Output is correct |
23 |
Correct |
89 ms |
36592 KB |
Output is correct |
24 |
Correct |
117 ms |
36604 KB |
Output is correct |
25 |
Correct |
106 ms |
36468 KB |
Output is correct |
26 |
Correct |
90 ms |
36340 KB |
Output is correct |
27 |
Correct |
156 ms |
37056 KB |
Output is correct |
28 |
Correct |
93 ms |
36464 KB |
Output is correct |
29 |
Correct |
98 ms |
36640 KB |
Output is correct |
30 |
Correct |
99 ms |
36596 KB |
Output is correct |
31 |
Correct |
112 ms |
36852 KB |
Output is correct |
32 |
Correct |
126 ms |
36456 KB |
Output is correct |
33 |
Correct |
141 ms |
36596 KB |
Output is correct |
34 |
Correct |
96 ms |
36476 KB |
Output is correct |
35 |
Correct |
126 ms |
36464 KB |
Output is correct |
36 |
Correct |
123 ms |
36472 KB |
Output is correct |
37 |
Correct |
111 ms |
36472 KB |
Output is correct |
38 |
Correct |
113 ms |
36584 KB |
Output is correct |
39 |
Correct |
131 ms |
36484 KB |
Output is correct |
40 |
Correct |
114 ms |
36472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
33108 KB |
Output is correct |
2 |
Correct |
82 ms |
33108 KB |
Output is correct |
3 |
Correct |
95 ms |
33104 KB |
Output is correct |
4 |
Correct |
80 ms |
33104 KB |
Output is correct |
5 |
Correct |
77 ms |
33204 KB |
Output is correct |
6 |
Correct |
79 ms |
33108 KB |
Output is correct |
7 |
Correct |
79 ms |
33100 KB |
Output is correct |
8 |
Correct |
79 ms |
33284 KB |
Output is correct |
9 |
Correct |
88 ms |
33108 KB |
Output is correct |
10 |
Correct |
81 ms |
33104 KB |
Output is correct |
11 |
Correct |
267 ms |
47956 KB |
Output is correct |
12 |
Correct |
314 ms |
47700 KB |
Output is correct |
13 |
Correct |
267 ms |
46924 KB |
Output is correct |
14 |
Correct |
263 ms |
46932 KB |
Output is correct |
15 |
Correct |
317 ms |
47948 KB |
Output is correct |
16 |
Correct |
289 ms |
47180 KB |
Output is correct |
17 |
Correct |
295 ms |
47360 KB |
Output is correct |
18 |
Correct |
1266 ms |
49168 KB |
Output is correct |
19 |
Correct |
235 ms |
45908 KB |
Output is correct |
20 |
Correct |
305 ms |
47704 KB |
Output is correct |
21 |
Correct |
398 ms |
51028 KB |
Output is correct |
22 |
Correct |
450 ms |
51152 KB |
Output is correct |
23 |
Correct |
299 ms |
50000 KB |
Output is correct |
24 |
Correct |
298 ms |
50004 KB |
Output is correct |
25 |
Correct |
534 ms |
52096 KB |
Output is correct |
26 |
Correct |
335 ms |
50508 KB |
Output is correct |
27 |
Correct |
341 ms |
50436 KB |
Output is correct |
28 |
Correct |
223 ms |
53308 KB |
Output is correct |
29 |
Correct |
267 ms |
48980 KB |
Output is correct |
30 |
Correct |
465 ms |
51284 KB |
Output is correct |
31 |
Correct |
353 ms |
50880 KB |
Output is correct |
32 |
Correct |
348 ms |
50772 KB |
Output is correct |
33 |
Correct |
290 ms |
50136 KB |
Output is correct |
34 |
Correct |
306 ms |
49840 KB |
Output is correct |
35 |
Correct |
367 ms |
50268 KB |
Output is correct |
36 |
Correct |
218 ms |
48976 KB |
Output is correct |
37 |
Correct |
337 ms |
51004 KB |
Output is correct |
38 |
Correct |
286 ms |
49236 KB |
Output is correct |
39 |
Correct |
319 ms |
50040 KB |
Output is correct |
40 |
Correct |
297 ms |
50004 KB |
Output is correct |
41 |
Correct |
155 ms |
36596 KB |
Output is correct |
42 |
Correct |
128 ms |
36628 KB |
Output is correct |
43 |
Correct |
96 ms |
36468 KB |
Output is correct |
44 |
Correct |
105 ms |
36592 KB |
Output is correct |
45 |
Correct |
91 ms |
36596 KB |
Output is correct |
46 |
Correct |
110 ms |
36592 KB |
Output is correct |
47 |
Correct |
115 ms |
36480 KB |
Output is correct |
48 |
Correct |
88 ms |
36728 KB |
Output is correct |
49 |
Correct |
92 ms |
36344 KB |
Output is correct |
50 |
Correct |
110 ms |
36724 KB |
Output is correct |
51 |
Correct |
172 ms |
36724 KB |
Output is correct |
52 |
Correct |
104 ms |
36596 KB |
Output is correct |
53 |
Correct |
89 ms |
36592 KB |
Output is correct |
54 |
Correct |
117 ms |
36604 KB |
Output is correct |
55 |
Correct |
106 ms |
36468 KB |
Output is correct |
56 |
Correct |
90 ms |
36340 KB |
Output is correct |
57 |
Correct |
156 ms |
37056 KB |
Output is correct |
58 |
Correct |
93 ms |
36464 KB |
Output is correct |
59 |
Correct |
98 ms |
36640 KB |
Output is correct |
60 |
Correct |
99 ms |
36596 KB |
Output is correct |
61 |
Correct |
112 ms |
36852 KB |
Output is correct |
62 |
Correct |
126 ms |
36456 KB |
Output is correct |
63 |
Correct |
141 ms |
36596 KB |
Output is correct |
64 |
Correct |
96 ms |
36476 KB |
Output is correct |
65 |
Correct |
126 ms |
36464 KB |
Output is correct |
66 |
Correct |
123 ms |
36472 KB |
Output is correct |
67 |
Correct |
111 ms |
36472 KB |
Output is correct |
68 |
Correct |
113 ms |
36584 KB |
Output is correct |
69 |
Correct |
131 ms |
36484 KB |
Output is correct |
70 |
Correct |
114 ms |
36472 KB |
Output is correct |
71 |
Correct |
1542 ms |
61032 KB |
Output is correct |
72 |
Correct |
1147 ms |
61044 KB |
Output is correct |
73 |
Correct |
429 ms |
59560 KB |
Output is correct |
74 |
Correct |
537 ms |
59944 KB |
Output is correct |
75 |
Correct |
350 ms |
61808 KB |
Output is correct |
76 |
Correct |
643 ms |
60148 KB |
Output is correct |
77 |
Correct |
629 ms |
60332 KB |
Output is correct |
78 |
Correct |
252 ms |
63596 KB |
Output is correct |
79 |
Correct |
317 ms |
57820 KB |
Output is correct |
80 |
Correct |
737 ms |
61076 KB |
Output is correct |
81 |
Correct |
1739 ms |
60840 KB |
Output is correct |
82 |
Correct |
566 ms |
59856 KB |
Output is correct |
83 |
Correct |
353 ms |
59140 KB |
Output is correct |
84 |
Correct |
475 ms |
60036 KB |
Output is correct |
85 |
Correct |
634 ms |
60216 KB |
Output is correct |
86 |
Correct |
241 ms |
57844 KB |
Output is correct |
87 |
Correct |
1562 ms |
61028 KB |
Output is correct |
88 |
Correct |
314 ms |
57988 KB |
Output is correct |
89 |
Correct |
439 ms |
59672 KB |
Output is correct |
90 |
Correct |
457 ms |
59796 KB |
Output is correct |
91 |
Correct |
334 ms |
59116 KB |
Output is correct |
92 |
Correct |
681 ms |
60132 KB |
Output is correct |
93 |
Correct |
636 ms |
60204 KB |
Output is correct |
94 |
Correct |
307 ms |
57896 KB |
Output is correct |
95 |
Correct |
700 ms |
59884 KB |
Output is correct |
96 |
Correct |
679 ms |
60132 KB |
Output is correct |
97 |
Correct |
674 ms |
59920 KB |
Output is correct |
98 |
Correct |
681 ms |
59948 KB |
Output is correct |
99 |
Correct |
680 ms |
60116 KB |
Output is correct |
100 |
Correct |
652 ms |
60084 KB |
Output is correct |