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>
#define F first
#define S second
#define LL int
#define MP make_pair
#define PB push_back
#define I insert
const LL N = 1600000;
using namespace std;
LL n, m, i, j, k, l, r, t, x, y;
LL a[N], dp[N], x3[20];
char c;
int main(){
x3[0] = 1;
for ( i = 1; i < 20; ++i ){
x3[i] = x3[i-1] * 3;
}
cin >> n >> m;
for ( i = 0; i < (1<<n); ++i ){
cin >> c;
a[i] = c - '0';
}
k = min(n,13);
for ( i = 0; i < x3[k]; ++i ){
t = i;
l = 0;
for ( j = 0; j < k; ++j ){
r = t % 3;
if ( r == 2 ){
dp[i] = dp[i - x3[j]] + dp[i - 2*x3[j]];
l = -100;
break;
}
l += (1<<(j)) * r;
t /= 3;
}
if ( l >= 0 ){
dp[i] = a[l];
}
//cout << i << " " << dp[i] << " " << l << endl;
}
while ( m-- ){
t = 0;
for ( i = 0; i < n; ++i ){
cin >> c;
t *= 3;
if ( c == '?' ) t += 2;
else t += c - '0';
}
cout << dp[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... |