#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define t3i tuple<long long, long long, long long>
int build(vector<int> &tri, vector<int> &ans, string &tox, int l, int q) {
int v = 0;
for (int i = 0; i < l; i++) {
v *= 3;
v += tri[i];
}
if (ans[v] != -1) return ans[v];
bool ok = 0;
for (int i = 0; i < l; i++) {
if (tri[i] == 2) {
int cans = 0;
tri[i] = 0;
cans += build(tri, ans, tox, l, q);
tri[i] = 1;
cans += build(tri, ans, tox, l, q);
tri[i] = 2;
ans[v] = cans;
ok = 1;
}
}
if (!ok) {
int bin = 0;
for (int i = 0; i < l; i++) {
bin *= 2;
bin += tri[i];
}
ans[v] = tox[bin] - '0';
}
return ans[v];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int l, q;
string tox;
cin >> l >> q >> tox;
vector<int> ans(pow(3, l) + 100, -1);
vector<int> tri(l, 2);
build(tri, ans, tox, l, q);
while (q--) {
string s;
cin >> s;
int v = 0;
for (int i = 0; i < l; i++) {
v *= 3;
v += (s[i] == '?' ? 2 : s[i] - '0');
}
cout << ans[v] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Correct |
136 ms |
15572 KB |
Output is correct |
12 |
Correct |
148 ms |
15188 KB |
Output is correct |
13 |
Correct |
129 ms |
14392 KB |
Output is correct |
14 |
Correct |
136 ms |
14416 KB |
Output is correct |
15 |
Correct |
130 ms |
15444 KB |
Output is correct |
16 |
Correct |
143 ms |
14620 KB |
Output is correct |
17 |
Correct |
140 ms |
14672 KB |
Output is correct |
18 |
Correct |
96 ms |
16468 KB |
Output is correct |
19 |
Correct |
102 ms |
13588 KB |
Output is correct |
20 |
Correct |
141 ms |
15188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Correct |
136 ms |
15572 KB |
Output is correct |
12 |
Correct |
148 ms |
15188 KB |
Output is correct |
13 |
Correct |
129 ms |
14392 KB |
Output is correct |
14 |
Correct |
136 ms |
14416 KB |
Output is correct |
15 |
Correct |
130 ms |
15444 KB |
Output is correct |
16 |
Correct |
143 ms |
14620 KB |
Output is correct |
17 |
Correct |
140 ms |
14672 KB |
Output is correct |
18 |
Correct |
96 ms |
16468 KB |
Output is correct |
19 |
Correct |
102 ms |
13588 KB |
Output is correct |
20 |
Correct |
141 ms |
15188 KB |
Output is correct |
21 |
Correct |
298 ms |
30544 KB |
Output is correct |
22 |
Correct |
313 ms |
30800 KB |
Output is correct |
23 |
Correct |
287 ms |
29776 KB |
Output is correct |
24 |
Correct |
285 ms |
29652 KB |
Output is correct |
25 |
Correct |
299 ms |
31428 KB |
Output is correct |
26 |
Correct |
333 ms |
30032 KB |
Output is correct |
27 |
Correct |
314 ms |
29892 KB |
Output is correct |
28 |
Correct |
259 ms |
32452 KB |
Output is correct |
29 |
Correct |
275 ms |
28612 KB |
Output is correct |
30 |
Correct |
310 ms |
30804 KB |
Output is correct |
31 |
Correct |
297 ms |
30416 KB |
Output is correct |
32 |
Correct |
294 ms |
30400 KB |
Output is correct |
33 |
Correct |
287 ms |
29524 KB |
Output is correct |
34 |
Correct |
289 ms |
29656 KB |
Output is correct |
35 |
Correct |
352 ms |
29908 KB |
Output is correct |
36 |
Correct |
268 ms |
28632 KB |
Output is correct |
37 |
Correct |
296 ms |
30484 KB |
Output is correct |
38 |
Correct |
281 ms |
28568 KB |
Output is correct |
39 |
Correct |
304 ms |
29780 KB |
Output is correct |
40 |
Correct |
303 ms |
29632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Runtime error |
5 ms |
4096 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
860 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
4 ms |
856 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Correct |
136 ms |
15572 KB |
Output is correct |
12 |
Correct |
148 ms |
15188 KB |
Output is correct |
13 |
Correct |
129 ms |
14392 KB |
Output is correct |
14 |
Correct |
136 ms |
14416 KB |
Output is correct |
15 |
Correct |
130 ms |
15444 KB |
Output is correct |
16 |
Correct |
143 ms |
14620 KB |
Output is correct |
17 |
Correct |
140 ms |
14672 KB |
Output is correct |
18 |
Correct |
96 ms |
16468 KB |
Output is correct |
19 |
Correct |
102 ms |
13588 KB |
Output is correct |
20 |
Correct |
141 ms |
15188 KB |
Output is correct |
21 |
Correct |
298 ms |
30544 KB |
Output is correct |
22 |
Correct |
313 ms |
30800 KB |
Output is correct |
23 |
Correct |
287 ms |
29776 KB |
Output is correct |
24 |
Correct |
285 ms |
29652 KB |
Output is correct |
25 |
Correct |
299 ms |
31428 KB |
Output is correct |
26 |
Correct |
333 ms |
30032 KB |
Output is correct |
27 |
Correct |
314 ms |
29892 KB |
Output is correct |
28 |
Correct |
259 ms |
32452 KB |
Output is correct |
29 |
Correct |
275 ms |
28612 KB |
Output is correct |
30 |
Correct |
310 ms |
30804 KB |
Output is correct |
31 |
Correct |
297 ms |
30416 KB |
Output is correct |
32 |
Correct |
294 ms |
30400 KB |
Output is correct |
33 |
Correct |
287 ms |
29524 KB |
Output is correct |
34 |
Correct |
289 ms |
29656 KB |
Output is correct |
35 |
Correct |
352 ms |
29908 KB |
Output is correct |
36 |
Correct |
268 ms |
28632 KB |
Output is correct |
37 |
Correct |
296 ms |
30484 KB |
Output is correct |
38 |
Correct |
281 ms |
28568 KB |
Output is correct |
39 |
Correct |
304 ms |
29780 KB |
Output is correct |
40 |
Correct |
303 ms |
29632 KB |
Output is correct |
41 |
Runtime error |
5 ms |
4096 KB |
Execution killed with signal 6 |
42 |
Halted |
0 ms |
0 KB |
- |