This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
int L,Q;
int ans[2000010];
string s;
int pw[14];
int getans(int mask) {
if (ans[mask]!=-1) return ans[mask];
int nmask = mask;
int tmp = 1;
while (nmask%3!=2) nmask/=3,tmp*=3;
return ans[mask] = getans(mask-tmp) + getans(mask-2*tmp);
}
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
pw[0]=1;
rep(i,1,14) pw[i] = pw[i-1]*3;
cin>>L>>Q;
cin>>s;
memset(ans,-1,sizeof(ans));
rep(i,0,(1<<L)) {
int cur = (int)(s[i]-'0');
int val = 0;
rep(j,0,L) {
val += ((i>>j)&1)*pw[j];
}
ans[val] = cur;
}
rep(mask,0,pw[L]) getans(mask);
while (Q--) {
string ss;cin>>ss;
int mask = 0;
rep(i,0,L) {
if (ss[L-1-i]=='1') mask+=pw[i];
else if (ss[L-1-i]=='?') mask+=pw[i]*2;
}
cout<<ans[mask]<<"\n";
}
return 0;
}
# | 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... |