This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |