This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 2e6+100, M = 1e5+10, K = 13, MX = 30;
int n, q, dp[N], p[15];
short int val[N][K];
string s;
void solve(){
cin >> n >> q >> s;
if(n > 13) return;
for(int i = 0; i < N; ++i) dp[i] = 0;
for(int i = 0; i < (1<<n); ++i){
int val = 0;
for(int j =0 ; j < n; ++j){
if((1<<j)&i) val += 2*p[j];
else val += p[j];
}
dp[val] += s[i] - '0';
}
// for(int i = 0; i < p[n]; ++i){
// cout << i << ": "; for(int j = 0; j < 5; ++j) cout << val[i][j];
// en;
// }
for(int i = 0; i < n; ++i){
for(int mask = 0; mask < p[n]; ++mask){
if(val[mask][i] == 0){
dp[mask] += dp[mask + p[i]];
dp[mask] += dp[mask + 2*p[i]];
}
}
}
for(int i = 0; i < q; ++i){
string t; cin >> t;
int val = 0;
for(int j = 0; j < n; ++j){
if(t[n - j - 1] == '0') val += p[j];
else if(t[n - j - 1] == '1') val += p[j] * 2;
}
cout << dp[val] << '\n';
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
p[0] = 1;
for(int i = 1; i <15; ++i) p[i] = p[i - 1] * 3;
for(int i = 0; i < N; ++i){
int x = i;
for(int j = 0; j < K; ++j){
val[i][j] = x % 3;
x /= 3;
}
}
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// cin >> tt;
while(tt--){
solve();
// en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message (stderr)
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:57:15: warning: unused variable 'aa' [-Wunused-variable]
57 | int tt = 1, aa;
| ^~
# | 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... |