/*
VENI VIDI VICI
*/
// #ifdef ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
using i128 = __int128;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
using sll = set<ll>;
template<class T>
istream& operator>>(istream& is, vector<T>& v) {
for(auto &i:v) is>>i;
return is;
}
template<class T1,class T2>
istream& operator>>(istream& is, pair<T1,T2>& p) {
is>>p.fi>>p.se;
return is;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for(const auto &i:v) os<<i<<' ';
return os;
}
template<class T1,class T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p) {
os<<p.fi<<' '<<p.se; return os;
}
void pyn(bool x)
{
cout<<(x?"YES":"NO")<<endl;
}
void pYN(bool x)
{
cout<<(x?"Yes":"No")<<endl;
}
void pAB(bool x)
{
cout<<(x?"Alice":"Bob")<<endl;
}
ll powmod(ll a,ll b,ll modulo)
{
if(b==0){
return 1;
}
ll temp=powmod(a,b/2,modulo);
if(b%2==0){
return (temp*temp)%modulo;
}
else{
return (a*((temp*temp)%modulo))%modulo;
}
}
bool Prime(ll n){
for (ll i = 2; i*i <= n; i++)
if (n % i == 0)
return false;
return (n>1);
}
void readIO() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
}
// #endif
void solve();
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
readIO();
int uwu=1;
// cin>>uwu;
for(int tc=1;tc<=uwu;tc++) {
// cout<<"Case #"<<tc<<": ";
solve();
}
return 0;
}
const int mod=1e9;
const int M=1600000+1,lg=20;
int dp[M],pw[lg];
void solve()
{
pw[0]=1;
for(int i=1;i<lg;i++)
{
pw[i]=pw[i-1]*3;
}
ll l,q;
cin>>l>>q;
for(int i=0;i<(1<<l);i++)
{
char c;
cin>>c;
int num=0;
for(int j=0;j<l;j++)
{
if((i>>j)&1)
{
num+=pw[j];
}
}
dp[num]=(c-'0');
}
for(int m=0;m<pw[l];m++) // 3^l
{
for(int i=0;i<l;i++) // l
{
int cb=(m/pw[i])%3;
if(cb==2)
{
dp[m]=dp[m-pw[i]]+dp[m-2*pw[i]]; // bit 0 and 1
break;
}
}
}
while(q--)
{
int num=0;
for(int i=l-1;i>=0;i--)
{
char c;
cin>>c;
if(c=='?')
{
num+=2*pw[i];
}
else if(c=='1')
{
num+=pw[i];
}
}
cout<<dp[num]<<endl;
}
}
| # | 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... |