이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int l,q,n;
cin>>l>>q; n=1<<l;
string s; cin>>s;
int tox[n];
for(int i=0; i<n; i++) tox[i] = s[i]-'0';
int pw[l+5]; pw[0]=1;
int k=1; for(int i=1; i<=l; i++){ k*=3; pw[i]=k;}
int ans[k]; memset(ans,0,sizeof(ans));
for(int ahc=0; ahc<k; ahc++){
vector<int> v; int cr=ahc;
for(int j=0; j<l; j++){
v.push_back(cr%3); cr/=3;
}
for(int i=0; i<n; i++){
bitset<13> b(i); bool f=1;
for(int j=0; j<l; j++){
if(v[j]!=2 && (b[j]!=v[j])){ f=0; break;}
}
if(f) ans[ahc] += tox[i];
}
}
for(int ahc=0; ahc<q; ahc++){
string s; cin>>s;
int qr=0;
for(int i=0; i<l; i++){
int pwer = l-i-1;
if(s[i]=='1') qr += (pw[pwer]);
if(s[i]=='?') qr += (2*pw[pwer]);
}
cout<<ans[qr]<<"\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... |