#include <iostream>
#include <vector>
int a[21][1<<20];
struct trie{
std::vector<int> res;
trie *next[3];
};
trie root;
int b[1000000];
void dfs(trie *p, int d, int s){
if(s == 1)
for(int x : p->res)
b[x] = a[d][0];
else{
if(p->next[0]){
for(int i=0; i<s/2; ++i)
a[d+1][i] = a[d][i];
dfs(p->next[0], d+1, s/2);
}
if(p->next[1]){
for(int i=0; i<s/2; ++i)
a[d+1][i] = a[d][i+s/2];
dfs(p->next[1], d+1, s/2);
}
if(p->next[2]){
for(int i=0; i<s/2; ++i)
a[d+1][i] = a[d][i+s/2];
for(int i=0; i<s/2; ++i)
a[d+1][i] += a[d][i];
dfs(p->next[2], d+1, s/2);
}
}
}
int main(){
std::cin.tie(0) -> sync_with_stdio(0);
int l, q; std::cin >> l >> q;
for(int i=0; i<1<<l; ++i){
char c; std::cin >> c;
a[0][i] = c-'0';
}
for(int i=0; i<q; ++i){
trie *p = &root;
for(int j=0; j<l; ++j){
char c; std::cin >> c;
int r = c == '?' ? 2 : c - '0';
if(!p->next[r]) p->next[r] = new trie();
p = p->next[r];
}
p->res.push_back(i);
}
dfs(&root, 0, 1<<l);
for(int i=0; i<q; ++i) std::cout << b[i] << " \n"[i==q-1];
}
# | 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... |