#include<bits/stdc++.h>
using namespace std;
const int maxn = (1<<20);
int n, q;
int sub[maxn], super[maxn], val[maxn];
int gt(char x){
if(x == '0' || x == '1')return x-'0';
else return 2;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> q;
for(int i = 0; i < (1<<n); i++){
char x;
cin >> x;
sub[i] = super[i] = val[i] = x-'0';
}
for(int i = 0; i < n; i++){
for(int j = 0; j < (1<<n); j++){
if(i&(1<<j)){
super[i^(1<<j)]+=super[i];
sub[i]+=sub[i^(1<<j)];
}
}
}
while(q--){
string str;
cin >> str;
reverse(str.begin(), str.end());
int mask[3] = {0, 0, 0};
int ans = 0;
for(int i = 0; i < n; i++){
mask[gt(str[i])]|=(1<<i);
}
if(__builtin_popcount(mask[2]) <= 10){
for(int i = mask[2];;i=(i-1)&mask[2]){
ans += val[i^mask[1]];
if(!i)break;
}
}
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 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 |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 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 |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 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 |
1247 ms |
12348 KB |
Output is correct |
12 |
Correct |
1295 ms |
11708 KB |
Output is correct |
13 |
Correct |
1243 ms |
11036 KB |
Output is correct |
14 |
Correct |
1232 ms |
11124 KB |
Output is correct |
15 |
Correct |
1273 ms |
12340 KB |
Output is correct |
16 |
Correct |
1241 ms |
11348 KB |
Output is correct |
17 |
Correct |
1261 ms |
11496 KB |
Output is correct |
18 |
Execution timed out |
2049 ms |
12628 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 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 |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 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 |
1247 ms |
12348 KB |
Output is correct |
12 |
Correct |
1295 ms |
11708 KB |
Output is correct |
13 |
Correct |
1243 ms |
11036 KB |
Output is correct |
14 |
Correct |
1232 ms |
11124 KB |
Output is correct |
15 |
Correct |
1273 ms |
12340 KB |
Output is correct |
16 |
Correct |
1241 ms |
11348 KB |
Output is correct |
17 |
Correct |
1261 ms |
11496 KB |
Output is correct |
18 |
Execution timed out |
2049 ms |
12628 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 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 |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 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 |
153 ms |
13396 KB |
Output is correct |
12 |
Incorrect |
126 ms |
13848 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 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 |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 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 |
1247 ms |
12348 KB |
Output is correct |
12 |
Correct |
1295 ms |
11708 KB |
Output is correct |
13 |
Correct |
1243 ms |
11036 KB |
Output is correct |
14 |
Correct |
1232 ms |
11124 KB |
Output is correct |
15 |
Correct |
1273 ms |
12340 KB |
Output is correct |
16 |
Correct |
1241 ms |
11348 KB |
Output is correct |
17 |
Correct |
1261 ms |
11496 KB |
Output is correct |
18 |
Execution timed out |
2049 ms |
12628 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |