// PhuThuyRuntime <3
// A secret makes a woman woman
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define ef emplace_front
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define fo(i, l, r) for(int i = l; i <= r; i++)
#define foi(i, l, r) for(int i = l; i >= r; i--)
#define elif else if
#define el cout << "\n";
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define fi first
#define se second
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define ll long long
#define ull unsigned long long
#define pob pop_back
#define bs binary_search
#define vi vector<int>
#define vii vector<pair<int, int>>
#define getbit(i, j) ((i >> j) & 1)
#define offbit(i, j) ((1 << j) ^ i)
#define onbit(i, j) ((1 << j) | i)
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
const int inf = INT_MAX;
const int base = 31;
const long double EPS = 1e-9;
const long double pi = acos(-1.0);
int n, Q;
char a[1 << 20];
void inp(){
cin >> n >> Q;
fo(i, 0, (1 << n) - 1) cin >> a[i];
}
int fin[1 << 20], fout[1 << 20];
void sol(){
fo(i, 0, (1 << n) - 1) fin[i] = fout[i] = a[i] - '0';
fo(i, 0, n - 1){
fo(mask, 0, (1 << n) - 1){
if(getbit(mask, i)){
fin[mask] += fin[offbit(mask, i)];
}
else fout[mask] += fout[onbit(mask, i)];
}
}
while(Q--){
int va = 0, vb = 0, vc = 0;
foi(i, n - 1, 0){
char ch; cin >> ch;
if(ch == '0') va |= 1 << i;
else if(ch == '1') vb |= 1 << i;
else vc |= 1 << i;
}
int cnta = __builtin_popcount(va);
int cntb = __builtin_popcount(vb);
int cntc = __builtin_popcount(vc);
if(cntc <= 6){
int ans = 0;
for(int mask = vc; mask; mask = vc & (mask - 1)){
ans += a[mask | vb] - '0';
}
ans += a[vb] - '0';
cout << ans, el
}
else if(cnta <= 6){
int ans = 0;
for(int mask = va; mask; mask = va & (mask - 1)){
int sign = __builtin_popcount(mask) & 1 ? -1 : 1;
ans += sign * fout[mask | vb];
}
ans += fout[vb];
cout << ans, el
}
else if(cntb <= 6){
int ans = 0;
for(int mask = vb; mask; mask = vb & (mask - 1)){
int sign = (cntb - __builtin_popcount(mask)) & 1 ? -1 : 1;
ans += sign * fin[mask | vc];
}
if(cntb & 1) ans -= fin[vc];
else ans += fin[vc];
cout << ans, el
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
inp();
sol();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
215 ms |
15188 KB |
Output is correct |
12 |
Correct |
235 ms |
14676 KB |
Output is correct |
13 |
Correct |
252 ms |
13904 KB |
Output is correct |
14 |
Correct |
239 ms |
14160 KB |
Output is correct |
15 |
Correct |
249 ms |
15036 KB |
Output is correct |
16 |
Correct |
283 ms |
14380 KB |
Output is correct |
17 |
Correct |
267 ms |
14160 KB |
Output is correct |
18 |
Correct |
142 ms |
16156 KB |
Output is correct |
19 |
Correct |
191 ms |
13136 KB |
Output is correct |
20 |
Correct |
240 ms |
14740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
215 ms |
15188 KB |
Output is correct |
12 |
Correct |
235 ms |
14676 KB |
Output is correct |
13 |
Correct |
252 ms |
13904 KB |
Output is correct |
14 |
Correct |
239 ms |
14160 KB |
Output is correct |
15 |
Correct |
249 ms |
15036 KB |
Output is correct |
16 |
Correct |
283 ms |
14380 KB |
Output is correct |
17 |
Correct |
267 ms |
14160 KB |
Output is correct |
18 |
Correct |
142 ms |
16156 KB |
Output is correct |
19 |
Correct |
191 ms |
13136 KB |
Output is correct |
20 |
Correct |
240 ms |
14740 KB |
Output is correct |
21 |
Correct |
278 ms |
18000 KB |
Output is correct |
22 |
Correct |
349 ms |
18256 KB |
Output is correct |
23 |
Correct |
309 ms |
17232 KB |
Output is correct |
24 |
Correct |
329 ms |
17236 KB |
Output is correct |
25 |
Correct |
257 ms |
19028 KB |
Output is correct |
26 |
Correct |
320 ms |
17536 KB |
Output is correct |
27 |
Correct |
332 ms |
17592 KB |
Output is correct |
28 |
Correct |
156 ms |
20048 KB |
Output is correct |
29 |
Correct |
241 ms |
16472 KB |
Output is correct |
30 |
Correct |
320 ms |
18512 KB |
Output is correct |
31 |
Correct |
336 ms |
18100 KB |
Output is correct |
32 |
Correct |
309 ms |
18220 KB |
Output is correct |
33 |
Correct |
260 ms |
16976 KB |
Output is correct |
34 |
Correct |
327 ms |
17036 KB |
Output is correct |
35 |
Correct |
351 ms |
17628 KB |
Output is correct |
36 |
Correct |
172 ms |
16128 KB |
Output is correct |
37 |
Correct |
305 ms |
18040 KB |
Output is correct |
38 |
Correct |
271 ms |
16072 KB |
Output is correct |
39 |
Correct |
327 ms |
17348 KB |
Output is correct |
40 |
Correct |
312 ms |
17024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
50 ms |
11752 KB |
Output is correct |
12 |
Correct |
47 ms |
11728 KB |
Output is correct |
13 |
Correct |
48 ms |
11772 KB |
Output is correct |
14 |
Correct |
61 ms |
11860 KB |
Output is correct |
15 |
Correct |
44 ms |
11888 KB |
Output is correct |
16 |
Correct |
58 ms |
11860 KB |
Output is correct |
17 |
Correct |
55 ms |
11860 KB |
Output is correct |
18 |
Correct |
50 ms |
12112 KB |
Output is correct |
19 |
Correct |
45 ms |
11600 KB |
Output is correct |
20 |
Correct |
46 ms |
11952 KB |
Output is correct |
21 |
Correct |
50 ms |
11860 KB |
Output is correct |
22 |
Correct |
59 ms |
11712 KB |
Output is correct |
23 |
Correct |
43 ms |
11700 KB |
Output is correct |
24 |
Correct |
56 ms |
11856 KB |
Output is correct |
25 |
Correct |
52 ms |
11860 KB |
Output is correct |
26 |
Correct |
39 ms |
11708 KB |
Output is correct |
27 |
Correct |
43 ms |
11856 KB |
Output is correct |
28 |
Correct |
44 ms |
11712 KB |
Output is correct |
29 |
Correct |
49 ms |
11736 KB |
Output is correct |
30 |
Correct |
65 ms |
11896 KB |
Output is correct |
31 |
Correct |
46 ms |
11860 KB |
Output is correct |
32 |
Correct |
56 ms |
11724 KB |
Output is correct |
33 |
Correct |
54 ms |
11860 KB |
Output is correct |
34 |
Correct |
36 ms |
11704 KB |
Output is correct |
35 |
Correct |
52 ms |
11856 KB |
Output is correct |
36 |
Correct |
49 ms |
11708 KB |
Output is correct |
37 |
Correct |
50 ms |
11856 KB |
Output is correct |
38 |
Correct |
54 ms |
11860 KB |
Output is correct |
39 |
Correct |
52 ms |
11856 KB |
Output is correct |
40 |
Correct |
55 ms |
11696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
215 ms |
15188 KB |
Output is correct |
12 |
Correct |
235 ms |
14676 KB |
Output is correct |
13 |
Correct |
252 ms |
13904 KB |
Output is correct |
14 |
Correct |
239 ms |
14160 KB |
Output is correct |
15 |
Correct |
249 ms |
15036 KB |
Output is correct |
16 |
Correct |
283 ms |
14380 KB |
Output is correct |
17 |
Correct |
267 ms |
14160 KB |
Output is correct |
18 |
Correct |
142 ms |
16156 KB |
Output is correct |
19 |
Correct |
191 ms |
13136 KB |
Output is correct |
20 |
Correct |
240 ms |
14740 KB |
Output is correct |
21 |
Correct |
278 ms |
18000 KB |
Output is correct |
22 |
Correct |
349 ms |
18256 KB |
Output is correct |
23 |
Correct |
309 ms |
17232 KB |
Output is correct |
24 |
Correct |
329 ms |
17236 KB |
Output is correct |
25 |
Correct |
257 ms |
19028 KB |
Output is correct |
26 |
Correct |
320 ms |
17536 KB |
Output is correct |
27 |
Correct |
332 ms |
17592 KB |
Output is correct |
28 |
Correct |
156 ms |
20048 KB |
Output is correct |
29 |
Correct |
241 ms |
16472 KB |
Output is correct |
30 |
Correct |
320 ms |
18512 KB |
Output is correct |
31 |
Correct |
336 ms |
18100 KB |
Output is correct |
32 |
Correct |
309 ms |
18220 KB |
Output is correct |
33 |
Correct |
260 ms |
16976 KB |
Output is correct |
34 |
Correct |
327 ms |
17036 KB |
Output is correct |
35 |
Correct |
351 ms |
17628 KB |
Output is correct |
36 |
Correct |
172 ms |
16128 KB |
Output is correct |
37 |
Correct |
305 ms |
18040 KB |
Output is correct |
38 |
Correct |
271 ms |
16072 KB |
Output is correct |
39 |
Correct |
327 ms |
17348 KB |
Output is correct |
40 |
Correct |
312 ms |
17024 KB |
Output is correct |
41 |
Correct |
50 ms |
11752 KB |
Output is correct |
42 |
Correct |
47 ms |
11728 KB |
Output is correct |
43 |
Correct |
48 ms |
11772 KB |
Output is correct |
44 |
Correct |
61 ms |
11860 KB |
Output is correct |
45 |
Correct |
44 ms |
11888 KB |
Output is correct |
46 |
Correct |
58 ms |
11860 KB |
Output is correct |
47 |
Correct |
55 ms |
11860 KB |
Output is correct |
48 |
Correct |
50 ms |
12112 KB |
Output is correct |
49 |
Correct |
45 ms |
11600 KB |
Output is correct |
50 |
Correct |
46 ms |
11952 KB |
Output is correct |
51 |
Correct |
50 ms |
11860 KB |
Output is correct |
52 |
Correct |
59 ms |
11712 KB |
Output is correct |
53 |
Correct |
43 ms |
11700 KB |
Output is correct |
54 |
Correct |
56 ms |
11856 KB |
Output is correct |
55 |
Correct |
52 ms |
11860 KB |
Output is correct |
56 |
Correct |
39 ms |
11708 KB |
Output is correct |
57 |
Correct |
43 ms |
11856 KB |
Output is correct |
58 |
Correct |
44 ms |
11712 KB |
Output is correct |
59 |
Correct |
49 ms |
11736 KB |
Output is correct |
60 |
Correct |
65 ms |
11896 KB |
Output is correct |
61 |
Correct |
46 ms |
11860 KB |
Output is correct |
62 |
Correct |
56 ms |
11724 KB |
Output is correct |
63 |
Correct |
54 ms |
11860 KB |
Output is correct |
64 |
Correct |
36 ms |
11704 KB |
Output is correct |
65 |
Correct |
52 ms |
11856 KB |
Output is correct |
66 |
Correct |
49 ms |
11708 KB |
Output is correct |
67 |
Correct |
50 ms |
11856 KB |
Output is correct |
68 |
Correct |
54 ms |
11860 KB |
Output is correct |
69 |
Correct |
52 ms |
11856 KB |
Output is correct |
70 |
Correct |
55 ms |
11696 KB |
Output is correct |
71 |
Correct |
393 ms |
36112 KB |
Output is correct |
72 |
Correct |
451 ms |
36132 KB |
Output is correct |
73 |
Correct |
489 ms |
34752 KB |
Output is correct |
74 |
Correct |
792 ms |
35056 KB |
Output is correct |
75 |
Correct |
400 ms |
37064 KB |
Output is correct |
76 |
Correct |
656 ms |
35448 KB |
Output is correct |
77 |
Correct |
600 ms |
35408 KB |
Output is correct |
78 |
Correct |
261 ms |
39116 KB |
Output is correct |
79 |
Correct |
391 ms |
33108 KB |
Output is correct |
80 |
Correct |
410 ms |
36184 KB |
Output is correct |
81 |
Correct |
528 ms |
36172 KB |
Output is correct |
82 |
Correct |
718 ms |
35192 KB |
Output is correct |
83 |
Correct |
383 ms |
34216 KB |
Output is correct |
84 |
Correct |
560 ms |
35156 KB |
Output is correct |
85 |
Correct |
595 ms |
35412 KB |
Output is correct |
86 |
Correct |
246 ms |
33004 KB |
Output is correct |
87 |
Correct |
402 ms |
36136 KB |
Output is correct |
88 |
Correct |
412 ms |
33108 KB |
Output is correct |
89 |
Correct |
469 ms |
34644 KB |
Output is correct |
90 |
Correct |
564 ms |
35180 KB |
Output is correct |
91 |
Correct |
388 ms |
34384 KB |
Output is correct |
92 |
Correct |
642 ms |
35412 KB |
Output is correct |
93 |
Correct |
614 ms |
35412 KB |
Output is correct |
94 |
Correct |
243 ms |
32972 KB |
Output is correct |
95 |
Correct |
500 ms |
35228 KB |
Output is correct |
96 |
Correct |
497 ms |
35108 KB |
Output is correct |
97 |
Correct |
502 ms |
35104 KB |
Output is correct |
98 |
Correct |
509 ms |
35272 KB |
Output is correct |
99 |
Correct |
524 ms |
35224 KB |
Output is correct |
100 |
Correct |
509 ms |
35152 KB |
Output is correct |