#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]) <= 6){
for(int i = mask[2];;i=(i-1)&mask[2]){
ans += val[i^mask[1]];
if(!i)break;
}
}
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |