#include <bits/stdc++.h>
using namespace std;
#define int long long
int arr[(1<<20)];
int sup[(1<<20)] = {0},super[(1<<20)] = {0};
signed main(){
int n,m;
cin>>n>>m;
string s;cin>>s;
for(int i = 0;i<(1<<n);i++){
sup[i] = super[i] = arr[i] = (s[i]-'0');
}
for(int i = 0;i<n;i++){
for(int mask = 0;mask<(1<<n);mask++){
if(mask&(1<<i)){
super[mask^(1<<i)]+=super[mask];
sup[mask]+=sup[mask^(1<<i)];
}
}
}
while(m--){
string s;cin>>s;
int zero = 0 , one = 0 , qu = 0;
for(int i = 0;i<n;i++){
if(s[i]=='0')zero+=(1<<(n-i-1));
else if(s[i]=='1')one+=(1<<(n-i-1));
else qu+=(1<<(n-i-1));
}
long long all = 0;
if(__builtin_popcount(qu)<=6){
for(int mask = qu;;mask=(qu&(mask-1))){
all+=arr[mask|one];
//cout<<mask<<endl;
if(mask==0)break;
}
}else if(__builtin_popcount(zero)<=6){
for(int mask = zero;;mask=(zero&(mask-1))){
if(__builtin_popcount(mask)&1)all-=super[mask|one];
else all+=super[mask|one];
if(mask==0)break;
}
}else {
for(int mask = one;;mask=(one&(mask-1))){
if(__builtin_popcount(mask)&1)all-=sup[mask^one^qu];
else all+=sup[mask^one^qu];
if(mask==0)break;
}
}
cout<<all<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
3 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
3 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
1464 ms |
8564 KB |
Output is correct |
12 |
Correct |
1515 ms |
8016 KB |
Output is correct |
13 |
Correct |
1478 ms |
7412 KB |
Output is correct |
14 |
Correct |
1465 ms |
7540 KB |
Output is correct |
15 |
Correct |
1518 ms |
8308 KB |
Output is correct |
16 |
Correct |
1548 ms |
7672 KB |
Output is correct |
17 |
Correct |
1539 ms |
7868 KB |
Output is correct |
18 |
Correct |
1481 ms |
9692 KB |
Output is correct |
19 |
Correct |
1479 ms |
6532 KB |
Output is correct |
20 |
Correct |
1465 ms |
8204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
3 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
1464 ms |
8564 KB |
Output is correct |
12 |
Correct |
1515 ms |
8016 KB |
Output is correct |
13 |
Correct |
1478 ms |
7412 KB |
Output is correct |
14 |
Correct |
1465 ms |
7540 KB |
Output is correct |
15 |
Correct |
1518 ms |
8308 KB |
Output is correct |
16 |
Correct |
1548 ms |
7672 KB |
Output is correct |
17 |
Correct |
1539 ms |
7868 KB |
Output is correct |
18 |
Correct |
1481 ms |
9692 KB |
Output is correct |
19 |
Correct |
1479 ms |
6532 KB |
Output is correct |
20 |
Correct |
1465 ms |
8204 KB |
Output is correct |
21 |
Correct |
1557 ms |
8516 KB |
Output is correct |
22 |
Correct |
1632 ms |
8912 KB |
Output is correct |
23 |
Correct |
1590 ms |
7744 KB |
Output is correct |
24 |
Correct |
1576 ms |
7388 KB |
Output is correct |
25 |
Correct |
1538 ms |
9596 KB |
Output is correct |
26 |
Correct |
1572 ms |
7928 KB |
Output is correct |
27 |
Correct |
1565 ms |
8072 KB |
Output is correct |
28 |
Correct |
1492 ms |
10428 KB |
Output is correct |
29 |
Correct |
1524 ms |
6704 KB |
Output is correct |
30 |
Correct |
1598 ms |
8788 KB |
Output is correct |
31 |
Correct |
1573 ms |
8596 KB |
Output is correct |
32 |
Correct |
1570 ms |
8744 KB |
Output is correct |
33 |
Correct |
1567 ms |
7476 KB |
Output is correct |
34 |
Correct |
1548 ms |
7436 KB |
Output is correct |
35 |
Correct |
1559 ms |
8308 KB |
Output is correct |
36 |
Correct |
1466 ms |
6432 KB |
Output is correct |
37 |
Correct |
1598 ms |
8680 KB |
Output is correct |
38 |
Correct |
1514 ms |
6452 KB |
Output is correct |
39 |
Correct |
1552 ms |
7796 KB |
Output is correct |
40 |
Correct |
1541 ms |
7424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
3 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
124 ms |
26436 KB |
Output is correct |
12 |
Correct |
124 ms |
26436 KB |
Output is correct |
13 |
Correct |
139 ms |
26356 KB |
Output is correct |
14 |
Correct |
154 ms |
26328 KB |
Output is correct |
15 |
Correct |
134 ms |
26436 KB |
Output is correct |
16 |
Correct |
145 ms |
26240 KB |
Output is correct |
17 |
Correct |
160 ms |
26188 KB |
Output is correct |
18 |
Correct |
141 ms |
26468 KB |
Output is correct |
19 |
Correct |
138 ms |
26468 KB |
Output is correct |
20 |
Correct |
132 ms |
26288 KB |
Output is correct |
21 |
Correct |
141 ms |
26436 KB |
Output is correct |
22 |
Correct |
137 ms |
26220 KB |
Output is correct |
23 |
Correct |
126 ms |
26188 KB |
Output is correct |
24 |
Correct |
134 ms |
26300 KB |
Output is correct |
25 |
Correct |
149 ms |
26224 KB |
Output is correct |
26 |
Correct |
133 ms |
26688 KB |
Output is correct |
27 |
Correct |
128 ms |
26436 KB |
Output is correct |
28 |
Correct |
131 ms |
26188 KB |
Output is correct |
29 |
Correct |
134 ms |
26180 KB |
Output is correct |
30 |
Correct |
134 ms |
26200 KB |
Output is correct |
31 |
Correct |
126 ms |
26188 KB |
Output is correct |
32 |
Correct |
163 ms |
26204 KB |
Output is correct |
33 |
Correct |
147 ms |
26216 KB |
Output is correct |
34 |
Correct |
122 ms |
26256 KB |
Output is correct |
35 |
Correct |
149 ms |
26224 KB |
Output is correct |
36 |
Correct |
148 ms |
26752 KB |
Output is correct |
37 |
Correct |
161 ms |
26188 KB |
Output is correct |
38 |
Correct |
135 ms |
26300 KB |
Output is correct |
39 |
Correct |
148 ms |
26476 KB |
Output is correct |
40 |
Correct |
146 ms |
26508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
3 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
1464 ms |
8564 KB |
Output is correct |
12 |
Correct |
1515 ms |
8016 KB |
Output is correct |
13 |
Correct |
1478 ms |
7412 KB |
Output is correct |
14 |
Correct |
1465 ms |
7540 KB |
Output is correct |
15 |
Correct |
1518 ms |
8308 KB |
Output is correct |
16 |
Correct |
1548 ms |
7672 KB |
Output is correct |
17 |
Correct |
1539 ms |
7868 KB |
Output is correct |
18 |
Correct |
1481 ms |
9692 KB |
Output is correct |
19 |
Correct |
1479 ms |
6532 KB |
Output is correct |
20 |
Correct |
1465 ms |
8204 KB |
Output is correct |
21 |
Correct |
1557 ms |
8516 KB |
Output is correct |
22 |
Correct |
1632 ms |
8912 KB |
Output is correct |
23 |
Correct |
1590 ms |
7744 KB |
Output is correct |
24 |
Correct |
1576 ms |
7388 KB |
Output is correct |
25 |
Correct |
1538 ms |
9596 KB |
Output is correct |
26 |
Correct |
1572 ms |
7928 KB |
Output is correct |
27 |
Correct |
1565 ms |
8072 KB |
Output is correct |
28 |
Correct |
1492 ms |
10428 KB |
Output is correct |
29 |
Correct |
1524 ms |
6704 KB |
Output is correct |
30 |
Correct |
1598 ms |
8788 KB |
Output is correct |
31 |
Correct |
1573 ms |
8596 KB |
Output is correct |
32 |
Correct |
1570 ms |
8744 KB |
Output is correct |
33 |
Correct |
1567 ms |
7476 KB |
Output is correct |
34 |
Correct |
1548 ms |
7436 KB |
Output is correct |
35 |
Correct |
1559 ms |
8308 KB |
Output is correct |
36 |
Correct |
1466 ms |
6432 KB |
Output is correct |
37 |
Correct |
1598 ms |
8680 KB |
Output is correct |
38 |
Correct |
1514 ms |
6452 KB |
Output is correct |
39 |
Correct |
1552 ms |
7796 KB |
Output is correct |
40 |
Correct |
1541 ms |
7424 KB |
Output is correct |
41 |
Correct |
124 ms |
26436 KB |
Output is correct |
42 |
Correct |
124 ms |
26436 KB |
Output is correct |
43 |
Correct |
139 ms |
26356 KB |
Output is correct |
44 |
Correct |
154 ms |
26328 KB |
Output is correct |
45 |
Correct |
134 ms |
26436 KB |
Output is correct |
46 |
Correct |
145 ms |
26240 KB |
Output is correct |
47 |
Correct |
160 ms |
26188 KB |
Output is correct |
48 |
Correct |
141 ms |
26468 KB |
Output is correct |
49 |
Correct |
138 ms |
26468 KB |
Output is correct |
50 |
Correct |
132 ms |
26288 KB |
Output is correct |
51 |
Correct |
141 ms |
26436 KB |
Output is correct |
52 |
Correct |
137 ms |
26220 KB |
Output is correct |
53 |
Correct |
126 ms |
26188 KB |
Output is correct |
54 |
Correct |
134 ms |
26300 KB |
Output is correct |
55 |
Correct |
149 ms |
26224 KB |
Output is correct |
56 |
Correct |
133 ms |
26688 KB |
Output is correct |
57 |
Correct |
128 ms |
26436 KB |
Output is correct |
58 |
Correct |
131 ms |
26188 KB |
Output is correct |
59 |
Correct |
134 ms |
26180 KB |
Output is correct |
60 |
Correct |
134 ms |
26200 KB |
Output is correct |
61 |
Correct |
126 ms |
26188 KB |
Output is correct |
62 |
Correct |
163 ms |
26204 KB |
Output is correct |
63 |
Correct |
147 ms |
26216 KB |
Output is correct |
64 |
Correct |
122 ms |
26256 KB |
Output is correct |
65 |
Correct |
149 ms |
26224 KB |
Output is correct |
66 |
Correct |
148 ms |
26752 KB |
Output is correct |
67 |
Correct |
161 ms |
26188 KB |
Output is correct |
68 |
Correct |
135 ms |
26300 KB |
Output is correct |
69 |
Correct |
148 ms |
26476 KB |
Output is correct |
70 |
Correct |
146 ms |
26508 KB |
Output is correct |
71 |
Correct |
1799 ms |
31552 KB |
Output is correct |
72 |
Correct |
1834 ms |
31596 KB |
Output is correct |
73 |
Correct |
1944 ms |
29904 KB |
Output is correct |
74 |
Execution timed out |
2051 ms |
50612 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |