#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];
int DP[1048576]; /// 0�� Ȯ��, 1�� 0and1
int DP2[1048576]; /// 1�� Ȯ��, 0�� 0and1
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(int d=0; d<n; d++){
for(int i=0; i<(1<<n); i++){
if(i & (1<<d)) DP[i] += DP[i^(1<<d)];
else DP2[i] += DP2[i|(1<<d)];
}
}
for(int i=1; i<=q; i++){
int one = 0;
int zero = 0;
int lft = 0;
cin >> str;
for(int j=n-1; j>=0; j--){
char c = str[n-1-j];
if(c=='1') one |= (1<<j);
else if(c=='0') zero |= (1<<j);
else lft |= (1<<j);
}
int 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 |
213 ms |
8360 KB |
Output is correct |
12 |
Correct |
222 ms |
7944 KB |
Output is correct |
13 |
Correct |
252 ms |
7160 KB |
Output is correct |
14 |
Correct |
244 ms |
7288 KB |
Output is correct |
15 |
Correct |
228 ms |
8348 KB |
Output is correct |
16 |
Correct |
258 ms |
7672 KB |
Output is correct |
17 |
Correct |
268 ms |
7416 KB |
Output is correct |
18 |
Correct |
172 ms |
9336 KB |
Output is correct |
19 |
Correct |
275 ms |
6264 KB |
Output is correct |
20 |
Correct |
222 ms |
7928 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 |
213 ms |
8360 KB |
Output is correct |
12 |
Correct |
222 ms |
7944 KB |
Output is correct |
13 |
Correct |
252 ms |
7160 KB |
Output is correct |
14 |
Correct |
244 ms |
7288 KB |
Output is correct |
15 |
Correct |
228 ms |
8348 KB |
Output is correct |
16 |
Correct |
258 ms |
7672 KB |
Output is correct |
17 |
Correct |
268 ms |
7416 KB |
Output is correct |
18 |
Correct |
172 ms |
9336 KB |
Output is correct |
19 |
Correct |
275 ms |
6264 KB |
Output is correct |
20 |
Correct |
222 ms |
7928 KB |
Output is correct |
21 |
Correct |
237 ms |
7672 KB |
Output is correct |
22 |
Correct |
246 ms |
7928 KB |
Output is correct |
23 |
Correct |
303 ms |
7028 KB |
Output is correct |
24 |
Correct |
297 ms |
6776 KB |
Output is correct |
25 |
Correct |
255 ms |
8824 KB |
Output is correct |
26 |
Correct |
317 ms |
7292 KB |
Output is correct |
27 |
Correct |
308 ms |
7240 KB |
Output is correct |
28 |
Correct |
187 ms |
9976 KB |
Output is correct |
29 |
Correct |
361 ms |
5824 KB |
Output is correct |
30 |
Correct |
247 ms |
8020 KB |
Output is correct |
31 |
Correct |
277 ms |
7956 KB |
Output is correct |
32 |
Correct |
281 ms |
7836 KB |
Output is correct |
33 |
Correct |
276 ms |
6904 KB |
Output is correct |
34 |
Correct |
296 ms |
6904 KB |
Output is correct |
35 |
Correct |
306 ms |
7288 KB |
Output is correct |
36 |
Correct |
175 ms |
5884 KB |
Output is correct |
37 |
Correct |
233 ms |
7872 KB |
Output is correct |
38 |
Correct |
318 ms |
5884 KB |
Output is correct |
39 |
Correct |
311 ms |
7032 KB |
Output is correct |
40 |
Correct |
292 ms |
7032 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 |
42 ms |
9848 KB |
Output is correct |
12 |
Correct |
46 ms |
11896 KB |
Output is correct |
13 |
Correct |
51 ms |
11768 KB |
Output is correct |
14 |
Correct |
56 ms |
12024 KB |
Output is correct |
15 |
Correct |
45 ms |
11896 KB |
Output is correct |
16 |
Correct |
61 ms |
11772 KB |
Output is correct |
17 |
Correct |
69 ms |
11896 KB |
Output is correct |
18 |
Correct |
39 ms |
12024 KB |
Output is correct |
19 |
Correct |
164 ms |
12024 KB |
Output is correct |
20 |
Correct |
47 ms |
12028 KB |
Output is correct |
21 |
Correct |
59 ms |
11896 KB |
Output is correct |
22 |
Correct |
63 ms |
11768 KB |
Output is correct |
23 |
Correct |
49 ms |
11896 KB |
Output is correct |
24 |
Correct |
70 ms |
11896 KB |
Output is correct |
25 |
Correct |
71 ms |
11896 KB |
Output is correct |
26 |
Correct |
50 ms |
11768 KB |
Output is correct |
27 |
Correct |
46 ms |
11896 KB |
Output is correct |
28 |
Correct |
102 ms |
11768 KB |
Output is correct |
29 |
Correct |
54 ms |
11768 KB |
Output is correct |
30 |
Correct |
61 ms |
11768 KB |
Output is correct |
31 |
Correct |
45 ms |
11768 KB |
Output is correct |
32 |
Correct |
58 ms |
11768 KB |
Output is correct |
33 |
Correct |
64 ms |
11768 KB |
Output is correct |
34 |
Correct |
45 ms |
11768 KB |
Output is correct |
35 |
Correct |
64 ms |
11768 KB |
Output is correct |
36 |
Correct |
70 ms |
11896 KB |
Output is correct |
37 |
Correct |
75 ms |
11768 KB |
Output is correct |
38 |
Correct |
66 ms |
11768 KB |
Output is correct |
39 |
Correct |
66 ms |
11768 KB |
Output is correct |
40 |
Correct |
65 ms |
11768 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 |
213 ms |
8360 KB |
Output is correct |
12 |
Correct |
222 ms |
7944 KB |
Output is correct |
13 |
Correct |
252 ms |
7160 KB |
Output is correct |
14 |
Correct |
244 ms |
7288 KB |
Output is correct |
15 |
Correct |
228 ms |
8348 KB |
Output is correct |
16 |
Correct |
258 ms |
7672 KB |
Output is correct |
17 |
Correct |
268 ms |
7416 KB |
Output is correct |
18 |
Correct |
172 ms |
9336 KB |
Output is correct |
19 |
Correct |
275 ms |
6264 KB |
Output is correct |
20 |
Correct |
222 ms |
7928 KB |
Output is correct |
21 |
Correct |
237 ms |
7672 KB |
Output is correct |
22 |
Correct |
246 ms |
7928 KB |
Output is correct |
23 |
Correct |
303 ms |
7028 KB |
Output is correct |
24 |
Correct |
297 ms |
6776 KB |
Output is correct |
25 |
Correct |
255 ms |
8824 KB |
Output is correct |
26 |
Correct |
317 ms |
7292 KB |
Output is correct |
27 |
Correct |
308 ms |
7240 KB |
Output is correct |
28 |
Correct |
187 ms |
9976 KB |
Output is correct |
29 |
Correct |
361 ms |
5824 KB |
Output is correct |
30 |
Correct |
247 ms |
8020 KB |
Output is correct |
31 |
Correct |
277 ms |
7956 KB |
Output is correct |
32 |
Correct |
281 ms |
7836 KB |
Output is correct |
33 |
Correct |
276 ms |
6904 KB |
Output is correct |
34 |
Correct |
296 ms |
6904 KB |
Output is correct |
35 |
Correct |
306 ms |
7288 KB |
Output is correct |
36 |
Correct |
175 ms |
5884 KB |
Output is correct |
37 |
Correct |
233 ms |
7872 KB |
Output is correct |
38 |
Correct |
318 ms |
5884 KB |
Output is correct |
39 |
Correct |
311 ms |
7032 KB |
Output is correct |
40 |
Correct |
292 ms |
7032 KB |
Output is correct |
41 |
Correct |
42 ms |
9848 KB |
Output is correct |
42 |
Correct |
46 ms |
11896 KB |
Output is correct |
43 |
Correct |
51 ms |
11768 KB |
Output is correct |
44 |
Correct |
56 ms |
12024 KB |
Output is correct |
45 |
Correct |
45 ms |
11896 KB |
Output is correct |
46 |
Correct |
61 ms |
11772 KB |
Output is correct |
47 |
Correct |
69 ms |
11896 KB |
Output is correct |
48 |
Correct |
39 ms |
12024 KB |
Output is correct |
49 |
Correct |
164 ms |
12024 KB |
Output is correct |
50 |
Correct |
47 ms |
12028 KB |
Output is correct |
51 |
Correct |
59 ms |
11896 KB |
Output is correct |
52 |
Correct |
63 ms |
11768 KB |
Output is correct |
53 |
Correct |
49 ms |
11896 KB |
Output is correct |
54 |
Correct |
70 ms |
11896 KB |
Output is correct |
55 |
Correct |
71 ms |
11896 KB |
Output is correct |
56 |
Correct |
50 ms |
11768 KB |
Output is correct |
57 |
Correct |
46 ms |
11896 KB |
Output is correct |
58 |
Correct |
102 ms |
11768 KB |
Output is correct |
59 |
Correct |
54 ms |
11768 KB |
Output is correct |
60 |
Correct |
61 ms |
11768 KB |
Output is correct |
61 |
Correct |
45 ms |
11768 KB |
Output is correct |
62 |
Correct |
58 ms |
11768 KB |
Output is correct |
63 |
Correct |
64 ms |
11768 KB |
Output is correct |
64 |
Correct |
45 ms |
11768 KB |
Output is correct |
65 |
Correct |
64 ms |
11768 KB |
Output is correct |
66 |
Correct |
70 ms |
11896 KB |
Output is correct |
67 |
Correct |
75 ms |
11768 KB |
Output is correct |
68 |
Correct |
66 ms |
11768 KB |
Output is correct |
69 |
Correct |
66 ms |
11768 KB |
Output is correct |
70 |
Correct |
65 ms |
11768 KB |
Output is correct |
71 |
Correct |
339 ms |
15224 KB |
Output is correct |
72 |
Correct |
357 ms |
15228 KB |
Output is correct |
73 |
Correct |
501 ms |
13816 KB |
Output is correct |
74 |
Correct |
527 ms |
14320 KB |
Output is correct |
75 |
Correct |
339 ms |
15992 KB |
Output is correct |
76 |
Correct |
750 ms |
16512 KB |
Output is correct |
77 |
Correct |
831 ms |
14412 KB |
Output is correct |
78 |
Correct |
261 ms |
18168 KB |
Output is correct |
79 |
Execution timed out |
2069 ms |
11624 KB |
Time limit exceeded |
80 |
Halted |
0 ms |
0 KB |
- |