#include <iostream>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
int n, q;
char arr[1048579];
char str[100], c;
int DP[1<<20]; /// 0�� Ȯ��, 1�� 0and1
int DP2[1<<20]; /// 1�� Ȯ��, 0�� 0and1
int one, zero, lft;
int ans, d, i;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
cin >> arr;
for(int i=0; i<(1<<n); i++){
DP[i] = DP2[i] = arr[i] - '0';
}
for(d=n-1;;d--){
for(i=(1<<n)-1;;i--){
if(i & (1<<d)) DP[i] += DP[i^(1<<d)];
else DP2[i] += DP2[i|(1<<d)];
if(!i) break;
}
if(!d) break;
}
while(q--){
one = zero = lft = 0;
cin >> str;
for(int j=n-1; j>=0; j--){
c = str[n-1-j];
if(c=='1') one |= (1<<j);
else if(c=='0') zero |= (1<<j);
else lft |= (1<<j);
}
if(!lft){
cout << arr[one] << '\n';
continue;
}
ans = 0;
if(__builtin_popcount(one) > __builtin_popcount(zero)){
for(int x=zero; 1; x = (x-1)&zero){
ans += DP2[one|x] * (__builtin_popcount(x) & 1 ? -1 : 1);
if(!x) break;
}
}
else{
for(int x=one; 1; x = (x-1)&one){
ans += DP[lft|x] * (__builtin_popcount(one ^ x) & 1 ? -1 : 1);
if(!x) break;
}
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
205 ms |
4352 KB |
Output is correct |
12 |
Correct |
233 ms |
4088 KB |
Output is correct |
13 |
Correct |
238 ms |
3316 KB |
Output is correct |
14 |
Correct |
303 ms |
3320 KB |
Output is correct |
15 |
Correct |
218 ms |
4344 KB |
Output is correct |
16 |
Correct |
253 ms |
3576 KB |
Output is correct |
17 |
Correct |
263 ms |
3568 KB |
Output is correct |
18 |
Correct |
185 ms |
5496 KB |
Output is correct |
19 |
Correct |
189 ms |
2428 KB |
Output is correct |
20 |
Correct |
218 ms |
4088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
205 ms |
4352 KB |
Output is correct |
12 |
Correct |
233 ms |
4088 KB |
Output is correct |
13 |
Correct |
238 ms |
3316 KB |
Output is correct |
14 |
Correct |
303 ms |
3320 KB |
Output is correct |
15 |
Correct |
218 ms |
4344 KB |
Output is correct |
16 |
Correct |
253 ms |
3576 KB |
Output is correct |
17 |
Correct |
263 ms |
3568 KB |
Output is correct |
18 |
Correct |
185 ms |
5496 KB |
Output is correct |
19 |
Correct |
189 ms |
2428 KB |
Output is correct |
20 |
Correct |
218 ms |
4088 KB |
Output is correct |
21 |
Correct |
228 ms |
4536 KB |
Output is correct |
22 |
Correct |
251 ms |
4728 KB |
Output is correct |
23 |
Correct |
302 ms |
3668 KB |
Output is correct |
24 |
Correct |
279 ms |
3704 KB |
Output is correct |
25 |
Correct |
249 ms |
5496 KB |
Output is correct |
26 |
Correct |
301 ms |
4088 KB |
Output is correct |
27 |
Correct |
313 ms |
3960 KB |
Output is correct |
28 |
Correct |
194 ms |
6520 KB |
Output is correct |
29 |
Correct |
209 ms |
2448 KB |
Output is correct |
30 |
Correct |
256 ms |
4668 KB |
Output is correct |
31 |
Correct |
276 ms |
4648 KB |
Output is correct |
32 |
Correct |
285 ms |
4472 KB |
Output is correct |
33 |
Correct |
271 ms |
3320 KB |
Output is correct |
34 |
Correct |
300 ms |
3532 KB |
Output is correct |
35 |
Correct |
312 ms |
3832 KB |
Output is correct |
36 |
Correct |
150 ms |
2424 KB |
Output is correct |
37 |
Correct |
235 ms |
4472 KB |
Output is correct |
38 |
Correct |
220 ms |
2552 KB |
Output is correct |
39 |
Correct |
309 ms |
3704 KB |
Output is correct |
40 |
Correct |
294 ms |
3508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
45 ms |
9848 KB |
Output is correct |
12 |
Correct |
52 ms |
9848 KB |
Output is correct |
13 |
Correct |
59 ms |
9720 KB |
Output is correct |
14 |
Correct |
53 ms |
9720 KB |
Output is correct |
15 |
Correct |
45 ms |
9848 KB |
Output is correct |
16 |
Correct |
60 ms |
9720 KB |
Output is correct |
17 |
Correct |
63 ms |
9740 KB |
Output is correct |
18 |
Correct |
40 ms |
10104 KB |
Output is correct |
19 |
Correct |
44 ms |
9720 KB |
Output is correct |
20 |
Correct |
46 ms |
9848 KB |
Output is correct |
21 |
Correct |
51 ms |
9808 KB |
Output is correct |
22 |
Correct |
51 ms |
9720 KB |
Output is correct |
23 |
Correct |
51 ms |
9720 KB |
Output is correct |
24 |
Correct |
61 ms |
9720 KB |
Output is correct |
25 |
Correct |
65 ms |
9720 KB |
Output is correct |
26 |
Correct |
51 ms |
9720 KB |
Output is correct |
27 |
Correct |
43 ms |
9856 KB |
Output is correct |
28 |
Correct |
42 ms |
9600 KB |
Output is correct |
29 |
Correct |
54 ms |
9720 KB |
Output is correct |
30 |
Correct |
58 ms |
9720 KB |
Output is correct |
31 |
Correct |
55 ms |
9720 KB |
Output is correct |
32 |
Correct |
55 ms |
9720 KB |
Output is correct |
33 |
Correct |
82 ms |
9720 KB |
Output is correct |
34 |
Correct |
51 ms |
9720 KB |
Output is correct |
35 |
Correct |
55 ms |
9820 KB |
Output is correct |
36 |
Correct |
70 ms |
9720 KB |
Output is correct |
37 |
Correct |
67 ms |
9720 KB |
Output is correct |
38 |
Correct |
70 ms |
9720 KB |
Output is correct |
39 |
Correct |
64 ms |
9720 KB |
Output is correct |
40 |
Correct |
56 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
205 ms |
4352 KB |
Output is correct |
12 |
Correct |
233 ms |
4088 KB |
Output is correct |
13 |
Correct |
238 ms |
3316 KB |
Output is correct |
14 |
Correct |
303 ms |
3320 KB |
Output is correct |
15 |
Correct |
218 ms |
4344 KB |
Output is correct |
16 |
Correct |
253 ms |
3576 KB |
Output is correct |
17 |
Correct |
263 ms |
3568 KB |
Output is correct |
18 |
Correct |
185 ms |
5496 KB |
Output is correct |
19 |
Correct |
189 ms |
2428 KB |
Output is correct |
20 |
Correct |
218 ms |
4088 KB |
Output is correct |
21 |
Correct |
228 ms |
4536 KB |
Output is correct |
22 |
Correct |
251 ms |
4728 KB |
Output is correct |
23 |
Correct |
302 ms |
3668 KB |
Output is correct |
24 |
Correct |
279 ms |
3704 KB |
Output is correct |
25 |
Correct |
249 ms |
5496 KB |
Output is correct |
26 |
Correct |
301 ms |
4088 KB |
Output is correct |
27 |
Correct |
313 ms |
3960 KB |
Output is correct |
28 |
Correct |
194 ms |
6520 KB |
Output is correct |
29 |
Correct |
209 ms |
2448 KB |
Output is correct |
30 |
Correct |
256 ms |
4668 KB |
Output is correct |
31 |
Correct |
276 ms |
4648 KB |
Output is correct |
32 |
Correct |
285 ms |
4472 KB |
Output is correct |
33 |
Correct |
271 ms |
3320 KB |
Output is correct |
34 |
Correct |
300 ms |
3532 KB |
Output is correct |
35 |
Correct |
312 ms |
3832 KB |
Output is correct |
36 |
Correct |
150 ms |
2424 KB |
Output is correct |
37 |
Correct |
235 ms |
4472 KB |
Output is correct |
38 |
Correct |
220 ms |
2552 KB |
Output is correct |
39 |
Correct |
309 ms |
3704 KB |
Output is correct |
40 |
Correct |
294 ms |
3508 KB |
Output is correct |
41 |
Correct |
45 ms |
9848 KB |
Output is correct |
42 |
Correct |
52 ms |
9848 KB |
Output is correct |
43 |
Correct |
59 ms |
9720 KB |
Output is correct |
44 |
Correct |
53 ms |
9720 KB |
Output is correct |
45 |
Correct |
45 ms |
9848 KB |
Output is correct |
46 |
Correct |
60 ms |
9720 KB |
Output is correct |
47 |
Correct |
63 ms |
9740 KB |
Output is correct |
48 |
Correct |
40 ms |
10104 KB |
Output is correct |
49 |
Correct |
44 ms |
9720 KB |
Output is correct |
50 |
Correct |
46 ms |
9848 KB |
Output is correct |
51 |
Correct |
51 ms |
9808 KB |
Output is correct |
52 |
Correct |
51 ms |
9720 KB |
Output is correct |
53 |
Correct |
51 ms |
9720 KB |
Output is correct |
54 |
Correct |
61 ms |
9720 KB |
Output is correct |
55 |
Correct |
65 ms |
9720 KB |
Output is correct |
56 |
Correct |
51 ms |
9720 KB |
Output is correct |
57 |
Correct |
43 ms |
9856 KB |
Output is correct |
58 |
Correct |
42 ms |
9600 KB |
Output is correct |
59 |
Correct |
54 ms |
9720 KB |
Output is correct |
60 |
Correct |
58 ms |
9720 KB |
Output is correct |
61 |
Correct |
55 ms |
9720 KB |
Output is correct |
62 |
Correct |
55 ms |
9720 KB |
Output is correct |
63 |
Correct |
82 ms |
9720 KB |
Output is correct |
64 |
Correct |
51 ms |
9720 KB |
Output is correct |
65 |
Correct |
55 ms |
9820 KB |
Output is correct |
66 |
Correct |
70 ms |
9720 KB |
Output is correct |
67 |
Correct |
67 ms |
9720 KB |
Output is correct |
68 |
Correct |
70 ms |
9720 KB |
Output is correct |
69 |
Correct |
64 ms |
9720 KB |
Output is correct |
70 |
Correct |
56 ms |
9720 KB |
Output is correct |
71 |
Correct |
378 ms |
14640 KB |
Output is correct |
72 |
Correct |
375 ms |
14712 KB |
Output is correct |
73 |
Correct |
481 ms |
13304 KB |
Output is correct |
74 |
Correct |
547 ms |
13596 KB |
Output is correct |
75 |
Correct |
363 ms |
15608 KB |
Output is correct |
76 |
Correct |
749 ms |
14028 KB |
Output is correct |
77 |
Correct |
786 ms |
13816 KB |
Output is correct |
78 |
Correct |
237 ms |
17656 KB |
Output is correct |
79 |
Correct |
333 ms |
17272 KB |
Output is correct |
80 |
Correct |
400 ms |
36216 KB |
Output is correct |
81 |
Correct |
504 ms |
36216 KB |
Output is correct |
82 |
Correct |
543 ms |
35192 KB |
Output is correct |
83 |
Correct |
397 ms |
34424 KB |
Output is correct |
84 |
Correct |
885 ms |
35576 KB |
Output is correct |
85 |
Correct |
768 ms |
35444 KB |
Output is correct |
86 |
Correct |
200 ms |
33144 KB |
Output is correct |
87 |
Correct |
375 ms |
36152 KB |
Output is correct |
88 |
Correct |
349 ms |
33100 KB |
Output is correct |
89 |
Correct |
655 ms |
34936 KB |
Output is correct |
90 |
Correct |
1096 ms |
35296 KB |
Output is correct |
91 |
Correct |
425 ms |
34468 KB |
Output is correct |
92 |
Correct |
784 ms |
35636 KB |
Output is correct |
93 |
Correct |
803 ms |
35448 KB |
Output is correct |
94 |
Correct |
239 ms |
33144 KB |
Output is correct |
95 |
Correct |
814 ms |
35280 KB |
Output is correct |
96 |
Correct |
649 ms |
35324 KB |
Output is correct |
97 |
Correct |
713 ms |
35192 KB |
Output is correct |
98 |
Correct |
678 ms |
35480 KB |
Output is correct |
99 |
Correct |
751 ms |
35152 KB |
Output is correct |
100 |
Correct |
681 ms |
35284 KB |
Output is correct |