#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)<=0){
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;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
4440 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
3 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
4440 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
3 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
1282 ms |
8636 KB |
Output is correct |
12 |
Correct |
1270 ms |
8108 KB |
Output is correct |
13 |
Correct |
1308 ms |
7252 KB |
Output is correct |
14 |
Correct |
1294 ms |
7376 KB |
Output is correct |
15 |
Correct |
1261 ms |
8496 KB |
Output is correct |
16 |
Correct |
1276 ms |
7564 KB |
Output is correct |
17 |
Correct |
1303 ms |
7512 KB |
Output is correct |
18 |
Correct |
1266 ms |
9424 KB |
Output is correct |
19 |
Correct |
1285 ms |
6520 KB |
Output is correct |
20 |
Correct |
1287 ms |
8440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
4440 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
3 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
1282 ms |
8636 KB |
Output is correct |
12 |
Correct |
1270 ms |
8108 KB |
Output is correct |
13 |
Correct |
1308 ms |
7252 KB |
Output is correct |
14 |
Correct |
1294 ms |
7376 KB |
Output is correct |
15 |
Correct |
1261 ms |
8496 KB |
Output is correct |
16 |
Correct |
1276 ms |
7564 KB |
Output is correct |
17 |
Correct |
1303 ms |
7512 KB |
Output is correct |
18 |
Correct |
1266 ms |
9424 KB |
Output is correct |
19 |
Correct |
1285 ms |
6520 KB |
Output is correct |
20 |
Correct |
1287 ms |
8440 KB |
Output is correct |
21 |
Correct |
1348 ms |
8800 KB |
Output is correct |
22 |
Correct |
1272 ms |
8564 KB |
Output is correct |
23 |
Correct |
1309 ms |
7664 KB |
Output is correct |
24 |
Correct |
1356 ms |
7616 KB |
Output is correct |
25 |
Correct |
1281 ms |
10152 KB |
Output is correct |
26 |
Correct |
1343 ms |
8168 KB |
Output is correct |
27 |
Correct |
1320 ms |
8068 KB |
Output is correct |
28 |
Correct |
1213 ms |
10392 KB |
Output is correct |
29 |
Correct |
1261 ms |
6396 KB |
Output is correct |
30 |
Correct |
1339 ms |
8760 KB |
Output is correct |
31 |
Correct |
1358 ms |
8424 KB |
Output is correct |
32 |
Correct |
1324 ms |
8552 KB |
Output is correct |
33 |
Correct |
1296 ms |
7512 KB |
Output is correct |
34 |
Correct |
1361 ms |
7540 KB |
Output is correct |
35 |
Correct |
1348 ms |
8376 KB |
Output is correct |
36 |
Correct |
1217 ms |
6404 KB |
Output is correct |
37 |
Correct |
1263 ms |
8716 KB |
Output is correct |
38 |
Correct |
1310 ms |
6728 KB |
Output is correct |
39 |
Correct |
1371 ms |
8104 KB |
Output is correct |
40 |
Correct |
1313 ms |
7504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
4440 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
3 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
92 ms |
14128 KB |
Output is correct |
12 |
Correct |
92 ms |
14068 KB |
Output is correct |
13 |
Incorrect |
98 ms |
13960 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
3 ms |
4440 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
3 ms |
4440 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
1282 ms |
8636 KB |
Output is correct |
12 |
Correct |
1270 ms |
8108 KB |
Output is correct |
13 |
Correct |
1308 ms |
7252 KB |
Output is correct |
14 |
Correct |
1294 ms |
7376 KB |
Output is correct |
15 |
Correct |
1261 ms |
8496 KB |
Output is correct |
16 |
Correct |
1276 ms |
7564 KB |
Output is correct |
17 |
Correct |
1303 ms |
7512 KB |
Output is correct |
18 |
Correct |
1266 ms |
9424 KB |
Output is correct |
19 |
Correct |
1285 ms |
6520 KB |
Output is correct |
20 |
Correct |
1287 ms |
8440 KB |
Output is correct |
21 |
Correct |
1348 ms |
8800 KB |
Output is correct |
22 |
Correct |
1272 ms |
8564 KB |
Output is correct |
23 |
Correct |
1309 ms |
7664 KB |
Output is correct |
24 |
Correct |
1356 ms |
7616 KB |
Output is correct |
25 |
Correct |
1281 ms |
10152 KB |
Output is correct |
26 |
Correct |
1343 ms |
8168 KB |
Output is correct |
27 |
Correct |
1320 ms |
8068 KB |
Output is correct |
28 |
Correct |
1213 ms |
10392 KB |
Output is correct |
29 |
Correct |
1261 ms |
6396 KB |
Output is correct |
30 |
Correct |
1339 ms |
8760 KB |
Output is correct |
31 |
Correct |
1358 ms |
8424 KB |
Output is correct |
32 |
Correct |
1324 ms |
8552 KB |
Output is correct |
33 |
Correct |
1296 ms |
7512 KB |
Output is correct |
34 |
Correct |
1361 ms |
7540 KB |
Output is correct |
35 |
Correct |
1348 ms |
8376 KB |
Output is correct |
36 |
Correct |
1217 ms |
6404 KB |
Output is correct |
37 |
Correct |
1263 ms |
8716 KB |
Output is correct |
38 |
Correct |
1310 ms |
6728 KB |
Output is correct |
39 |
Correct |
1371 ms |
8104 KB |
Output is correct |
40 |
Correct |
1313 ms |
7504 KB |
Output is correct |
41 |
Correct |
92 ms |
14128 KB |
Output is correct |
42 |
Correct |
92 ms |
14068 KB |
Output is correct |
43 |
Incorrect |
98 ms |
13960 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |