#include <bits/stdc++.h>
using namespace std;
int N, L, Q, T;
int arr[1<<20];
int dp[60000][1<<10];
vector<int> ternary[60000];
int pows[20];
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> L >> Q;
N = 1<<L;
for(int m = 0; m<N; m++){
char c;
cin >> c;
arr[m] = c-'0';
}
int H = L/2;
T = 1;
pows[0] = 1;
for(int k = 0; k<H; k++){
T *= 3;
pows[k+1] = pows[k] * 3;
}
for(int m = 0; m<T; m++){
int temp = m;
for(int k = 0; k<H; k++){
ternary[m].emplace_back(temp%3);
temp /= 3;
}
}
for(int m = 0; m<1<<(L-H); m++){
for(int t = 0; t<T; t++){
bool has2 = 0;
int temp = 0;
for(int h = 0; h<H; h++){
if(ternary[t][h] == 2){
has2 = 1;
dp[t][m] = dp[t-pows[h]][m] + dp[t-pows[h]*2][m];
break;
}
temp += (1<<h)*ternary[t][h];
}
if(!has2){
dp[t][m] = arr[(temp<<(L-H)) + m];
}
}
}
while(Q--){
string s;
cin >> s;
int t = 0;
vector<int> qu;
for(int i = 0; i<L; i++){
if(s[i] == '?'){
qu.emplace_back(2);
}
else{
qu.emplace_back(s[i]-'0');
}
}
for(int k = 0; k<H; k++){
t *= 3;
t += qu[k];
}
reverse(qu.begin(), qu.end());
long long out = 0;
for(int m = 0; m<1<<(L-H); m++){
bool good = 1;
for(int b = 0; b<L-H; b++){
if(qu[b] == 2 || qu[b] == ((m>>b)&1)){
}
else{
good = 0;
break;
}
}
if(good){
out += dp[t][m];
}
}
cout << out << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
7 ms |
2944 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
7 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2816 KB |
Output is correct |
10 |
Correct |
7 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
7 ms |
2944 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
7 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2816 KB |
Output is correct |
10 |
Correct |
7 ms |
2816 KB |
Output is correct |
11 |
Correct |
692 ms |
17528 KB |
Output is correct |
12 |
Correct |
706 ms |
17144 KB |
Output is correct |
13 |
Correct |
634 ms |
16504 KB |
Output is correct |
14 |
Correct |
654 ms |
16504 KB |
Output is correct |
15 |
Correct |
703 ms |
17528 KB |
Output is correct |
16 |
Correct |
681 ms |
16760 KB |
Output is correct |
17 |
Correct |
687 ms |
16632 KB |
Output is correct |
18 |
Correct |
607 ms |
18552 KB |
Output is correct |
19 |
Correct |
527 ms |
15608 KB |
Output is correct |
20 |
Correct |
693 ms |
17272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
7 ms |
2944 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
7 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2816 KB |
Output is correct |
10 |
Correct |
7 ms |
2816 KB |
Output is correct |
11 |
Correct |
692 ms |
17528 KB |
Output is correct |
12 |
Correct |
706 ms |
17144 KB |
Output is correct |
13 |
Correct |
634 ms |
16504 KB |
Output is correct |
14 |
Correct |
654 ms |
16504 KB |
Output is correct |
15 |
Correct |
703 ms |
17528 KB |
Output is correct |
16 |
Correct |
681 ms |
16760 KB |
Output is correct |
17 |
Correct |
687 ms |
16632 KB |
Output is correct |
18 |
Correct |
607 ms |
18552 KB |
Output is correct |
19 |
Correct |
527 ms |
15608 KB |
Output is correct |
20 |
Correct |
693 ms |
17272 KB |
Output is correct |
21 |
Correct |
1472 ms |
22520 KB |
Output is correct |
22 |
Correct |
1450 ms |
22776 KB |
Output is correct |
23 |
Correct |
1245 ms |
21696 KB |
Output is correct |
24 |
Correct |
1279 ms |
21624 KB |
Output is correct |
25 |
Correct |
1511 ms |
23544 KB |
Output is correct |
26 |
Correct |
1327 ms |
22008 KB |
Output is correct |
27 |
Correct |
1329 ms |
22012 KB |
Output is correct |
28 |
Correct |
1353 ms |
24440 KB |
Output is correct |
29 |
Correct |
879 ms |
20472 KB |
Output is correct |
30 |
Correct |
1425 ms |
22648 KB |
Output is correct |
31 |
Correct |
1426 ms |
22520 KB |
Output is correct |
32 |
Correct |
1353 ms |
22520 KB |
Output is correct |
33 |
Correct |
1132 ms |
21368 KB |
Output is correct |
34 |
Correct |
1265 ms |
21496 KB |
Output is correct |
35 |
Correct |
1326 ms |
22008 KB |
Output is correct |
36 |
Correct |
849 ms |
20472 KB |
Output is correct |
37 |
Correct |
1411 ms |
22520 KB |
Output is correct |
38 |
Correct |
878 ms |
20472 KB |
Output is correct |
39 |
Correct |
1236 ms |
21624 KB |
Output is correct |
40 |
Correct |
1264 ms |
21496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
7 ms |
2944 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
7 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2816 KB |
Output is correct |
10 |
Correct |
7 ms |
2816 KB |
Output is correct |
11 |
Runtime error |
74 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2816 KB |
Output is correct |
2 |
Correct |
7 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2816 KB |
Output is correct |
4 |
Correct |
7 ms |
2944 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
7 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
7 ms |
2816 KB |
Output is correct |
9 |
Correct |
7 ms |
2816 KB |
Output is correct |
10 |
Correct |
7 ms |
2816 KB |
Output is correct |
11 |
Correct |
692 ms |
17528 KB |
Output is correct |
12 |
Correct |
706 ms |
17144 KB |
Output is correct |
13 |
Correct |
634 ms |
16504 KB |
Output is correct |
14 |
Correct |
654 ms |
16504 KB |
Output is correct |
15 |
Correct |
703 ms |
17528 KB |
Output is correct |
16 |
Correct |
681 ms |
16760 KB |
Output is correct |
17 |
Correct |
687 ms |
16632 KB |
Output is correct |
18 |
Correct |
607 ms |
18552 KB |
Output is correct |
19 |
Correct |
527 ms |
15608 KB |
Output is correct |
20 |
Correct |
693 ms |
17272 KB |
Output is correct |
21 |
Correct |
1472 ms |
22520 KB |
Output is correct |
22 |
Correct |
1450 ms |
22776 KB |
Output is correct |
23 |
Correct |
1245 ms |
21696 KB |
Output is correct |
24 |
Correct |
1279 ms |
21624 KB |
Output is correct |
25 |
Correct |
1511 ms |
23544 KB |
Output is correct |
26 |
Correct |
1327 ms |
22008 KB |
Output is correct |
27 |
Correct |
1329 ms |
22012 KB |
Output is correct |
28 |
Correct |
1353 ms |
24440 KB |
Output is correct |
29 |
Correct |
879 ms |
20472 KB |
Output is correct |
30 |
Correct |
1425 ms |
22648 KB |
Output is correct |
31 |
Correct |
1426 ms |
22520 KB |
Output is correct |
32 |
Correct |
1353 ms |
22520 KB |
Output is correct |
33 |
Correct |
1132 ms |
21368 KB |
Output is correct |
34 |
Correct |
1265 ms |
21496 KB |
Output is correct |
35 |
Correct |
1326 ms |
22008 KB |
Output is correct |
36 |
Correct |
849 ms |
20472 KB |
Output is correct |
37 |
Correct |
1411 ms |
22520 KB |
Output is correct |
38 |
Correct |
878 ms |
20472 KB |
Output is correct |
39 |
Correct |
1236 ms |
21624 KB |
Output is correct |
40 |
Correct |
1264 ms |
21496 KB |
Output is correct |
41 |
Runtime error |
74 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
42 |
Halted |
0 ms |
0 KB |
- |