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;
#define int long long
const int INF = INT64_MAX;
int arr[8192];
char str[13];
int L;
int ask(int perm){
int idx = 0;
for(int x=0;x<L;x++){
if(str[x]=='1')idx|=(1<<x);
else if(str[x]=='?'){idx|=((perm&1)<<x);perm>>=1;}
}
return arr[idx];
}
int32_t main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q;
cin >> L >> q;
for(int i=0;i<(1<<L);i++){
char a;cin>>a;a-='0';
arr[i]=a;
}
map<string,int> memo;
for (int i = 0; i < q; i++) {
for(int j=L-1;j>=0;j--)cin>>str[j];
if(memo.count(str)){cout<<memo[str]<<'\n';continue;}
int n = count(str, str+L,'?');
int ans = 0;
for(int perm = 0;perm<(1<<n);perm++){
ans+=ask(perm);
}
cout << ans << '\n';
memo[str]=ans;
}
}
# | 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... |