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;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
int answer[(1<<10)][(1<<10)];
int main(){
int l,q;
cin>>l>>q;
string R;
cin>>R;
rep(i,0,(1<<10)){
rep(j,0,(1<<10)){
answer[i][j]=-1;
}
}
while(q--){
string s;
cin>>s;
int b,t;
b=0;
t=0;
rep(i,0,l){
if(s[i]=='1'){
b+=(1<<(l-1-i));
t+=(1<<(l-1-i));
}
if(s[i]=='?'){
t+=(1<<(l-1-i));
}
}
if(answer[b][t]!=-1)cout<<answer[b][t]<<endl;
else{
answer[b][t]=0;
rep(i,0,(1<<l)){
if(((i&b)==b) && ((i&t)==i)){
//cout<<b<<" "<<t<<" "<<i<<" "<<R[i]<<endl;
answer[b][t]+=R[i]-'0';
}
}
cout<<answer[b][t]<<endl;
}
}
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... |