#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
int arr[(1<<20)];
int sup[(1<<20)] = {0},super[(1<<20)] = {0};
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
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(one)<=6) {
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;
}
}else 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;
}
}
cout<<all<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 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 |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 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 |
4444 KB |
Output is correct |
11 |
Correct |
1281 ms |
8540 KB |
Output is correct |
12 |
Correct |
1285 ms |
8148 KB |
Output is correct |
13 |
Correct |
1270 ms |
7448 KB |
Output is correct |
14 |
Correct |
1259 ms |
7552 KB |
Output is correct |
15 |
Correct |
1259 ms |
8540 KB |
Output is correct |
16 |
Correct |
1300 ms |
7852 KB |
Output is correct |
17 |
Correct |
1339 ms |
7672 KB |
Output is correct |
18 |
Correct |
1235 ms |
9644 KB |
Output is correct |
19 |
Correct |
1297 ms |
6496 KB |
Output is correct |
20 |
Correct |
1296 ms |
8208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 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 |
4444 KB |
Output is correct |
11 |
Correct |
1281 ms |
8540 KB |
Output is correct |
12 |
Correct |
1285 ms |
8148 KB |
Output is correct |
13 |
Correct |
1270 ms |
7448 KB |
Output is correct |
14 |
Correct |
1259 ms |
7552 KB |
Output is correct |
15 |
Correct |
1259 ms |
8540 KB |
Output is correct |
16 |
Correct |
1300 ms |
7852 KB |
Output is correct |
17 |
Correct |
1339 ms |
7672 KB |
Output is correct |
18 |
Correct |
1235 ms |
9644 KB |
Output is correct |
19 |
Correct |
1297 ms |
6496 KB |
Output is correct |
20 |
Correct |
1296 ms |
8208 KB |
Output is correct |
21 |
Correct |
1357 ms |
8736 KB |
Output is correct |
22 |
Correct |
1283 ms |
8664 KB |
Output is correct |
23 |
Correct |
1354 ms |
7640 KB |
Output is correct |
24 |
Correct |
1315 ms |
7788 KB |
Output is correct |
25 |
Correct |
1287 ms |
9680 KB |
Output is correct |
26 |
Correct |
1342 ms |
8172 KB |
Output is correct |
27 |
Correct |
1334 ms |
8068 KB |
Output is correct |
28 |
Correct |
1234 ms |
10640 KB |
Output is correct |
29 |
Correct |
1272 ms |
6804 KB |
Output is correct |
30 |
Correct |
1351 ms |
8680 KB |
Output is correct |
31 |
Correct |
1373 ms |
8496 KB |
Output is correct |
32 |
Correct |
1326 ms |
8600 KB |
Output is correct |
33 |
Correct |
1288 ms |
7380 KB |
Output is correct |
34 |
Correct |
1358 ms |
7648 KB |
Output is correct |
35 |
Correct |
1344 ms |
8216 KB |
Output is correct |
36 |
Correct |
1232 ms |
6488 KB |
Output is correct |
37 |
Correct |
1275 ms |
8664 KB |
Output is correct |
38 |
Correct |
1316 ms |
6412 KB |
Output is correct |
39 |
Correct |
1398 ms |
7740 KB |
Output is correct |
40 |
Correct |
1324 ms |
7512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 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 |
4444 KB |
Output is correct |
11 |
Correct |
92 ms |
14000 KB |
Output is correct |
12 |
Correct |
92 ms |
13924 KB |
Output is correct |
13 |
Correct |
100 ms |
14252 KB |
Output is correct |
14 |
Correct |
103 ms |
14068 KB |
Output is correct |
15 |
Correct |
93 ms |
14132 KB |
Output is correct |
16 |
Correct |
104 ms |
14088 KB |
Output is correct |
17 |
Correct |
102 ms |
14016 KB |
Output is correct |
18 |
Correct |
92 ms |
14452 KB |
Output is correct |
19 |
Correct |
105 ms |
13988 KB |
Output is correct |
20 |
Correct |
95 ms |
14068 KB |
Output is correct |
21 |
Correct |
102 ms |
14068 KB |
Output is correct |
22 |
Correct |
105 ms |
14036 KB |
Output is correct |
23 |
Correct |
97 ms |
13960 KB |
Output is correct |
24 |
Correct |
124 ms |
14056 KB |
Output is correct |
25 |
Correct |
105 ms |
14108 KB |
Output is correct |
26 |
Correct |
90 ms |
13968 KB |
Output is correct |
27 |
Correct |
95 ms |
14064 KB |
Output is correct |
28 |
Correct |
97 ms |
13936 KB |
Output is correct |
29 |
Correct |
128 ms |
13952 KB |
Output is correct |
30 |
Correct |
149 ms |
13940 KB |
Output is correct |
31 |
Correct |
97 ms |
14072 KB |
Output is correct |
32 |
Correct |
143 ms |
14064 KB |
Output is correct |
33 |
Correct |
115 ms |
14076 KB |
Output is correct |
34 |
Correct |
92 ms |
13820 KB |
Output is correct |
35 |
Correct |
98 ms |
14052 KB |
Output is correct |
36 |
Correct |
99 ms |
14064 KB |
Output is correct |
37 |
Correct |
104 ms |
13944 KB |
Output is correct |
38 |
Correct |
99 ms |
13932 KB |
Output is correct |
39 |
Correct |
113 ms |
14068 KB |
Output is correct |
40 |
Correct |
102 ms |
14068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 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 |
4444 KB |
Output is correct |
11 |
Correct |
1281 ms |
8540 KB |
Output is correct |
12 |
Correct |
1285 ms |
8148 KB |
Output is correct |
13 |
Correct |
1270 ms |
7448 KB |
Output is correct |
14 |
Correct |
1259 ms |
7552 KB |
Output is correct |
15 |
Correct |
1259 ms |
8540 KB |
Output is correct |
16 |
Correct |
1300 ms |
7852 KB |
Output is correct |
17 |
Correct |
1339 ms |
7672 KB |
Output is correct |
18 |
Correct |
1235 ms |
9644 KB |
Output is correct |
19 |
Correct |
1297 ms |
6496 KB |
Output is correct |
20 |
Correct |
1296 ms |
8208 KB |
Output is correct |
21 |
Correct |
1357 ms |
8736 KB |
Output is correct |
22 |
Correct |
1283 ms |
8664 KB |
Output is correct |
23 |
Correct |
1354 ms |
7640 KB |
Output is correct |
24 |
Correct |
1315 ms |
7788 KB |
Output is correct |
25 |
Correct |
1287 ms |
9680 KB |
Output is correct |
26 |
Correct |
1342 ms |
8172 KB |
Output is correct |
27 |
Correct |
1334 ms |
8068 KB |
Output is correct |
28 |
Correct |
1234 ms |
10640 KB |
Output is correct |
29 |
Correct |
1272 ms |
6804 KB |
Output is correct |
30 |
Correct |
1351 ms |
8680 KB |
Output is correct |
31 |
Correct |
1373 ms |
8496 KB |
Output is correct |
32 |
Correct |
1326 ms |
8600 KB |
Output is correct |
33 |
Correct |
1288 ms |
7380 KB |
Output is correct |
34 |
Correct |
1358 ms |
7648 KB |
Output is correct |
35 |
Correct |
1344 ms |
8216 KB |
Output is correct |
36 |
Correct |
1232 ms |
6488 KB |
Output is correct |
37 |
Correct |
1275 ms |
8664 KB |
Output is correct |
38 |
Correct |
1316 ms |
6412 KB |
Output is correct |
39 |
Correct |
1398 ms |
7740 KB |
Output is correct |
40 |
Correct |
1324 ms |
7512 KB |
Output is correct |
41 |
Correct |
92 ms |
14000 KB |
Output is correct |
42 |
Correct |
92 ms |
13924 KB |
Output is correct |
43 |
Correct |
100 ms |
14252 KB |
Output is correct |
44 |
Correct |
103 ms |
14068 KB |
Output is correct |
45 |
Correct |
93 ms |
14132 KB |
Output is correct |
46 |
Correct |
104 ms |
14088 KB |
Output is correct |
47 |
Correct |
102 ms |
14016 KB |
Output is correct |
48 |
Correct |
92 ms |
14452 KB |
Output is correct |
49 |
Correct |
105 ms |
13988 KB |
Output is correct |
50 |
Correct |
95 ms |
14068 KB |
Output is correct |
51 |
Correct |
102 ms |
14068 KB |
Output is correct |
52 |
Correct |
105 ms |
14036 KB |
Output is correct |
53 |
Correct |
97 ms |
13960 KB |
Output is correct |
54 |
Correct |
124 ms |
14056 KB |
Output is correct |
55 |
Correct |
105 ms |
14108 KB |
Output is correct |
56 |
Correct |
90 ms |
13968 KB |
Output is correct |
57 |
Correct |
95 ms |
14064 KB |
Output is correct |
58 |
Correct |
97 ms |
13936 KB |
Output is correct |
59 |
Correct |
128 ms |
13952 KB |
Output is correct |
60 |
Correct |
149 ms |
13940 KB |
Output is correct |
61 |
Correct |
97 ms |
14072 KB |
Output is correct |
62 |
Correct |
143 ms |
14064 KB |
Output is correct |
63 |
Correct |
115 ms |
14076 KB |
Output is correct |
64 |
Correct |
92 ms |
13820 KB |
Output is correct |
65 |
Correct |
98 ms |
14052 KB |
Output is correct |
66 |
Correct |
99 ms |
14064 KB |
Output is correct |
67 |
Correct |
104 ms |
13944 KB |
Output is correct |
68 |
Correct |
99 ms |
13932 KB |
Output is correct |
69 |
Correct |
113 ms |
14068 KB |
Output is correct |
70 |
Correct |
102 ms |
14068 KB |
Output is correct |
71 |
Correct |
1415 ms |
18912 KB |
Output is correct |
72 |
Correct |
1428 ms |
18944 KB |
Output is correct |
73 |
Correct |
1525 ms |
17640 KB |
Output is correct |
74 |
Correct |
1631 ms |
18000 KB |
Output is correct |
75 |
Correct |
1431 ms |
19760 KB |
Output is correct |
76 |
Correct |
1578 ms |
18464 KB |
Output is correct |
77 |
Correct |
1652 ms |
18600 KB |
Output is correct |
78 |
Correct |
1330 ms |
21936 KB |
Output is correct |
79 |
Correct |
1446 ms |
15880 KB |
Output is correct |
80 |
Correct |
1497 ms |
18948 KB |
Output is correct |
81 |
Correct |
1485 ms |
18784 KB |
Output is correct |
82 |
Correct |
1573 ms |
17964 KB |
Output is correct |
83 |
Correct |
1418 ms |
17096 KB |
Output is correct |
84 |
Correct |
1584 ms |
18208 KB |
Output is correct |
85 |
Correct |
1607 ms |
17964 KB |
Output is correct |
86 |
Correct |
1320 ms |
15752 KB |
Output is correct |
87 |
Correct |
1478 ms |
18880 KB |
Output is correct |
88 |
Correct |
1474 ms |
15912 KB |
Output is correct |
89 |
Correct |
1508 ms |
17836 KB |
Output is correct |
90 |
Correct |
1534 ms |
39488 KB |
Output is correct |
91 |
Correct |
1450 ms |
38680 KB |
Output is correct |
92 |
Correct |
1587 ms |
40064 KB |
Output is correct |
93 |
Correct |
1734 ms |
39784 KB |
Output is correct |
94 |
Correct |
1359 ms |
37412 KB |
Output is correct |
95 |
Correct |
1595 ms |
39596 KB |
Output is correct |
96 |
Correct |
1588 ms |
39556 KB |
Output is correct |
97 |
Correct |
1663 ms |
39624 KB |
Output is correct |
98 |
Correct |
1544 ms |
39528 KB |
Output is correct |
99 |
Correct |
1564 ms |
39652 KB |
Output is correct |
100 |
Correct |
1627 ms |
39568 KB |
Output is correct |