#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[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int L, Q; cin >> L >> Q;
int* v = new int[1<<L];
for(int i = 0; i < (1<<L); i++){
char c; cin >> c;
v[i] = c-'0';
}
int** dp = new int*[p3[L]];
for(int i = 0; i < p3[L]; i++){
dp[i] = new int[L+1];
fill(dp[i], dp[i]+L+1, 0);
}
for(int i = 0; i < (1<<L); i++){
int x = 0;
for(int j = 0; j < L; j++) if(i&(1<<j)) x+=p3[j];
dp[x][0]+=v[i];
}
for(int i = 0; i < p3[L]; i++) for(int j = 1; j <= L; j++){
int x = (i/p3[j-1])%3;
if(x < 2)
dp[i][j] = dp[i][j-1];
else
dp[i][j] = dp[i-p3[j-1]*2][j-1]+dp[i-p3[j-1]][j-1];
}
while(Q--){
str s; cin >> s;
reverse(s.begin(), s.end());
int x = 0;
for(int i = 0; i < L; i++){
if(s[i] == '?') x+=p3[i]*2;
else x+=(s[i]-'0')*p3[i];
}
cout << dp[x][L] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4472 KB |
Output is correct |
2 |
Correct |
7 ms |
4436 KB |
Output is correct |
3 |
Correct |
9 ms |
4436 KB |
Output is correct |
4 |
Correct |
8 ms |
4500 KB |
Output is correct |
5 |
Correct |
8 ms |
4436 KB |
Output is correct |
6 |
Correct |
9 ms |
4436 KB |
Output is correct |
7 |
Correct |
7 ms |
4436 KB |
Output is correct |
8 |
Correct |
7 ms |
4436 KB |
Output is correct |
9 |
Correct |
7 ms |
4436 KB |
Output is correct |
10 |
Correct |
8 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4472 KB |
Output is correct |
2 |
Correct |
7 ms |
4436 KB |
Output is correct |
3 |
Correct |
9 ms |
4436 KB |
Output is correct |
4 |
Correct |
8 ms |
4500 KB |
Output is correct |
5 |
Correct |
8 ms |
4436 KB |
Output is correct |
6 |
Correct |
9 ms |
4436 KB |
Output is correct |
7 |
Correct |
7 ms |
4436 KB |
Output is correct |
8 |
Correct |
7 ms |
4436 KB |
Output is correct |
9 |
Correct |
7 ms |
4436 KB |
Output is correct |
10 |
Correct |
8 ms |
4436 KB |
Output is correct |
11 |
Correct |
190 ms |
8416 KB |
Output is correct |
12 |
Correct |
206 ms |
8108 KB |
Output is correct |
13 |
Correct |
202 ms |
7384 KB |
Output is correct |
14 |
Correct |
201 ms |
7512 KB |
Output is correct |
15 |
Correct |
190 ms |
8436 KB |
Output is correct |
16 |
Correct |
197 ms |
7664 KB |
Output is correct |
17 |
Correct |
213 ms |
7536 KB |
Output is correct |
18 |
Correct |
147 ms |
9480 KB |
Output is correct |
19 |
Correct |
145 ms |
6476 KB |
Output is correct |
20 |
Correct |
199 ms |
8252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4472 KB |
Output is correct |
2 |
Correct |
7 ms |
4436 KB |
Output is correct |
3 |
Correct |
9 ms |
4436 KB |
Output is correct |
4 |
Correct |
8 ms |
4500 KB |
Output is correct |
5 |
Correct |
8 ms |
4436 KB |
Output is correct |
6 |
Correct |
9 ms |
4436 KB |
Output is correct |
7 |
Correct |
7 ms |
4436 KB |
Output is correct |
8 |
Correct |
7 ms |
4436 KB |
Output is correct |
9 |
Correct |
7 ms |
4436 KB |
Output is correct |
10 |
Correct |
8 ms |
4436 KB |
Output is correct |
11 |
Correct |
190 ms |
8416 KB |
Output is correct |
12 |
Correct |
206 ms |
8108 KB |
Output is correct |
13 |
Correct |
202 ms |
7384 KB |
Output is correct |
14 |
Correct |
201 ms |
7512 KB |
Output is correct |
15 |
Correct |
190 ms |
8436 KB |
Output is correct |
16 |
Correct |
197 ms |
7664 KB |
Output is correct |
17 |
Correct |
213 ms |
7536 KB |
Output is correct |
18 |
Correct |
147 ms |
9480 KB |
Output is correct |
19 |
Correct |
145 ms |
6476 KB |
Output is correct |
20 |
Correct |
199 ms |
8252 KB |
Output is correct |
21 |
Runtime error |
57 ms |
65536 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4472 KB |
Output is correct |
2 |
Correct |
7 ms |
4436 KB |
Output is correct |
3 |
Correct |
9 ms |
4436 KB |
Output is correct |
4 |
Correct |
8 ms |
4500 KB |
Output is correct |
5 |
Correct |
8 ms |
4436 KB |
Output is correct |
6 |
Correct |
9 ms |
4436 KB |
Output is correct |
7 |
Correct |
7 ms |
4436 KB |
Output is correct |
8 |
Correct |
7 ms |
4436 KB |
Output is correct |
9 |
Correct |
7 ms |
4436 KB |
Output is correct |
10 |
Correct |
8 ms |
4436 KB |
Output is correct |
11 |
Runtime error |
19 ms |
8916 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4472 KB |
Output is correct |
2 |
Correct |
7 ms |
4436 KB |
Output is correct |
3 |
Correct |
9 ms |
4436 KB |
Output is correct |
4 |
Correct |
8 ms |
4500 KB |
Output is correct |
5 |
Correct |
8 ms |
4436 KB |
Output is correct |
6 |
Correct |
9 ms |
4436 KB |
Output is correct |
7 |
Correct |
7 ms |
4436 KB |
Output is correct |
8 |
Correct |
7 ms |
4436 KB |
Output is correct |
9 |
Correct |
7 ms |
4436 KB |
Output is correct |
10 |
Correct |
8 ms |
4436 KB |
Output is correct |
11 |
Correct |
190 ms |
8416 KB |
Output is correct |
12 |
Correct |
206 ms |
8108 KB |
Output is correct |
13 |
Correct |
202 ms |
7384 KB |
Output is correct |
14 |
Correct |
201 ms |
7512 KB |
Output is correct |
15 |
Correct |
190 ms |
8436 KB |
Output is correct |
16 |
Correct |
197 ms |
7664 KB |
Output is correct |
17 |
Correct |
213 ms |
7536 KB |
Output is correct |
18 |
Correct |
147 ms |
9480 KB |
Output is correct |
19 |
Correct |
145 ms |
6476 KB |
Output is correct |
20 |
Correct |
199 ms |
8252 KB |
Output is correct |
21 |
Runtime error |
57 ms |
65536 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |