#include <bits/stdc++.h>
using namespace std;
const int B = 12, N = 1<<20, SZ = pow(3, B);
int Q, dp[SZ], ans[N];
string A, t[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> Q >> Q >> A;
A.resize(N, '0');
for(int i = 0; i < Q; ++i) {
cin >> t[i];
reverse(begin(t[i]), end(t[i]));
t[i].resize(20, '0');
}
for(int s = 0; s < (1<<(20-B)); ++s) {
memset(dp, 0, sizeof dp);
for(int i = 0; i < (1<<B); ++i) {
int j = 0;
for(int k = 0, p = 1; k < B; ++k, p *= 3)
if(i & (1<<k)) j += p;
dp[j] += A[i | (s << B)] - '0';
}
for(int i = 1; i < SZ; ++i) {
int j = -1, pw = 1;
for(int k = 0, p = i; k < B; ++k, p /= 3, pw *= 3)
if((p % 3) > 1) j = k, k = B;
if(j >= 0)
pw /= 3, dp[i] = dp[i - pw] + dp[i - 2 * pw];
}
for(int i = 0; i < Q; ++i) {
bool OK = 1;
for(int k = 0; k < (20-B); ++k)
if(t[i][B+k] != '?' && bool(s & (1<<k)) != (t[i][B+k] - '0'))
OK = 0;
if(OK) {
int id = 0;
for(int k = 0, p = 1; k < B; ++k, p *= 3)
id += p * ((48 < t[i][k]) + (62 < t[i][k]));
ans[i] += dp[id];
}
}
}
for(int i = 0; i < Q; ++i)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
36304 KB |
Output is correct |
2 |
Correct |
678 ms |
36304 KB |
Output is correct |
3 |
Correct |
651 ms |
36304 KB |
Output is correct |
4 |
Correct |
646 ms |
36308 KB |
Output is correct |
5 |
Correct |
674 ms |
36420 KB |
Output is correct |
6 |
Correct |
657 ms |
36300 KB |
Output is correct |
7 |
Correct |
665 ms |
36320 KB |
Output is correct |
8 |
Correct |
656 ms |
36312 KB |
Output is correct |
9 |
Correct |
646 ms |
36300 KB |
Output is correct |
10 |
Correct |
682 ms |
36420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
36304 KB |
Output is correct |
2 |
Correct |
678 ms |
36304 KB |
Output is correct |
3 |
Correct |
651 ms |
36304 KB |
Output is correct |
4 |
Correct |
646 ms |
36308 KB |
Output is correct |
5 |
Correct |
674 ms |
36420 KB |
Output is correct |
6 |
Correct |
657 ms |
36300 KB |
Output is correct |
7 |
Correct |
665 ms |
36320 KB |
Output is correct |
8 |
Correct |
656 ms |
36312 KB |
Output is correct |
9 |
Correct |
646 ms |
36300 KB |
Output is correct |
10 |
Correct |
682 ms |
36420 KB |
Output is correct |
11 |
Runtime error |
116 ms |
65540 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
36304 KB |
Output is correct |
2 |
Correct |
678 ms |
36304 KB |
Output is correct |
3 |
Correct |
651 ms |
36304 KB |
Output is correct |
4 |
Correct |
646 ms |
36308 KB |
Output is correct |
5 |
Correct |
674 ms |
36420 KB |
Output is correct |
6 |
Correct |
657 ms |
36300 KB |
Output is correct |
7 |
Correct |
665 ms |
36320 KB |
Output is correct |
8 |
Correct |
656 ms |
36312 KB |
Output is correct |
9 |
Correct |
646 ms |
36300 KB |
Output is correct |
10 |
Correct |
682 ms |
36420 KB |
Output is correct |
11 |
Runtime error |
116 ms |
65540 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
36304 KB |
Output is correct |
2 |
Correct |
678 ms |
36304 KB |
Output is correct |
3 |
Correct |
651 ms |
36304 KB |
Output is correct |
4 |
Correct |
646 ms |
36308 KB |
Output is correct |
5 |
Correct |
674 ms |
36420 KB |
Output is correct |
6 |
Correct |
657 ms |
36300 KB |
Output is correct |
7 |
Correct |
665 ms |
36320 KB |
Output is correct |
8 |
Correct |
656 ms |
36312 KB |
Output is correct |
9 |
Correct |
646 ms |
36300 KB |
Output is correct |
10 |
Correct |
682 ms |
36420 KB |
Output is correct |
11 |
Correct |
1305 ms |
38936 KB |
Output is correct |
12 |
Correct |
1310 ms |
39140 KB |
Output is correct |
13 |
Correct |
1045 ms |
38932 KB |
Output is correct |
14 |
Correct |
1186 ms |
38932 KB |
Output is correct |
15 |
Correct |
1249 ms |
39060 KB |
Output is correct |
16 |
Correct |
1191 ms |
38932 KB |
Output is correct |
17 |
Correct |
1238 ms |
38928 KB |
Output is correct |
18 |
Correct |
956 ms |
39188 KB |
Output is correct |
19 |
Correct |
834 ms |
38928 KB |
Output is correct |
20 |
Correct |
1292 ms |
39060 KB |
Output is correct |
21 |
Correct |
1271 ms |
38936 KB |
Output is correct |
22 |
Correct |
1261 ms |
38932 KB |
Output is correct |
23 |
Correct |
964 ms |
39012 KB |
Output is correct |
24 |
Correct |
1152 ms |
39008 KB |
Output is correct |
25 |
Correct |
1181 ms |
38936 KB |
Output is correct |
26 |
Correct |
779 ms |
38844 KB |
Output is correct |
27 |
Correct |
1274 ms |
38932 KB |
Output is correct |
28 |
Correct |
803 ms |
38808 KB |
Output is correct |
29 |
Correct |
1097 ms |
38928 KB |
Output is correct |
30 |
Correct |
1150 ms |
38932 KB |
Output is correct |
31 |
Correct |
976 ms |
38960 KB |
Output is correct |
32 |
Correct |
1257 ms |
38932 KB |
Output is correct |
33 |
Correct |
1245 ms |
38928 KB |
Output is correct |
34 |
Correct |
793 ms |
38804 KB |
Output is correct |
35 |
Correct |
1181 ms |
38936 KB |
Output is correct |
36 |
Correct |
1163 ms |
38936 KB |
Output is correct |
37 |
Correct |
1168 ms |
38928 KB |
Output is correct |
38 |
Correct |
1195 ms |
38928 KB |
Output is correct |
39 |
Correct |
1141 ms |
39000 KB |
Output is correct |
40 |
Correct |
1157 ms |
38932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
36304 KB |
Output is correct |
2 |
Correct |
678 ms |
36304 KB |
Output is correct |
3 |
Correct |
651 ms |
36304 KB |
Output is correct |
4 |
Correct |
646 ms |
36308 KB |
Output is correct |
5 |
Correct |
674 ms |
36420 KB |
Output is correct |
6 |
Correct |
657 ms |
36300 KB |
Output is correct |
7 |
Correct |
665 ms |
36320 KB |
Output is correct |
8 |
Correct |
656 ms |
36312 KB |
Output is correct |
9 |
Correct |
646 ms |
36300 KB |
Output is correct |
10 |
Correct |
682 ms |
36420 KB |
Output is correct |
11 |
Runtime error |
116 ms |
65540 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |