#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int p3[16] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907};
int v[1<<20];
vector<pair<int, int>> queries[1<<7];
int dp[1594323];
void bruteforce(str &s, int &x, int &i, int k = 0, int index = 0){
if(k == 7){
queries[index].pb({x, i});
return;
}
if(s[13+k] != '1') bruteforce(s, x, i, k+1, index);
if(s[13+k] != '0') bruteforce(s, x, i, k+1, index+(1<<k));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int L, Q; cin >> L >> Q;
for(int i = 0; i < (1<<L); i++){
char c; cin >> c;
v[i] = c-'0';
}
vector<int> ans(Q, 0);
for(int i = 0; i < Q; i++){
str s; cin >> s;
if(L < 20) s = str(20-L, '0')+s;
reverse(s.begin(), s.end());
int x = 0;
for(int j = 0; j < 13; j++){
if(s[j] == '?') x+=p3[j]*2;
else x+=(s[j]-'0')*p3[j];
}
bruteforce(s, x, i);
}
for(int k = 0; k < (1<<7); k++){
if(queries[k].empty()) continue;
fill(dp, dp+p3[13], 0);
for(int i = k*(1<<7); i < (k+1)*(1<<7); i++){
int x = 0;
for(int j = 0; j < 13; j++) if(i&(1<<j)) x+=p3[j];
dp[x]+=v[i];
}
for(int j = 0; j < 13; j++) for(int i = 0; i < p3[13]; i++){
if((i/p3[j])%3 == 2){
dp[i]+=dp[i-p3[j]*2]+dp[i-p3[j]];
}
}
for(auto [x, i]: queries[k]) ans[i]+=dp[x];
}
for(int x: ans) cout << x << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
6580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
6580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
6580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
6580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
129 ms |
6580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |