#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<utility>
#define int long long
#define INF 1000000000000000000
#define pii pair<long long, long long>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q, pn;
cin >> n >> q;
string s, c;
cin >> s;
vector<int>t(25); t[0] = 1;
for (int i = 1 ; i < 25 ; i++) t[i] = t[i-1] * 3;
pn = t[n];
vector<int>dp(pn+5, -1);
int k = 0;
for (int i = 0 ; i < pn ; i++) {
for (int j = 0 ; j < n ; j++) {
int tmp = i / t[j] % 3;
if (tmp == 2) {
dp[i] = dp[i-t[j]] + dp[i-t[j]*2];
break;
}
}
//cout << dp[i] << " ";
if (dp[i] == -1) {
dp[i] = s[k] - '0';
k++;
}
//cout << dp[i] << "\n";
}
while (q--) {
cin >> c;
int ask = 0;
for (int i = 0 ; i < n ; i++) {
if (c[i] == '1') ask += 1 * t[n-i-1];
else if (c[i] == '?') ask += 2 * t[n-i-1];
}
cout << dp[ask] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
712 KB |
Output is correct |
11 |
Correct |
162 ms |
15692 KB |
Output is correct |
12 |
Correct |
165 ms |
15324 KB |
Output is correct |
13 |
Correct |
175 ms |
14512 KB |
Output is correct |
14 |
Correct |
177 ms |
14588 KB |
Output is correct |
15 |
Correct |
171 ms |
15700 KB |
Output is correct |
16 |
Correct |
185 ms |
14676 KB |
Output is correct |
17 |
Correct |
188 ms |
14932 KB |
Output is correct |
18 |
Correct |
130 ms |
16468 KB |
Output is correct |
19 |
Correct |
149 ms |
13648 KB |
Output is correct |
20 |
Correct |
176 ms |
15208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
712 KB |
Output is correct |
11 |
Correct |
162 ms |
15692 KB |
Output is correct |
12 |
Correct |
165 ms |
15324 KB |
Output is correct |
13 |
Correct |
175 ms |
14512 KB |
Output is correct |
14 |
Correct |
177 ms |
14588 KB |
Output is correct |
15 |
Correct |
171 ms |
15700 KB |
Output is correct |
16 |
Correct |
185 ms |
14676 KB |
Output is correct |
17 |
Correct |
188 ms |
14932 KB |
Output is correct |
18 |
Correct |
130 ms |
16468 KB |
Output is correct |
19 |
Correct |
149 ms |
13648 KB |
Output is correct |
20 |
Correct |
176 ms |
15208 KB |
Output is correct |
21 |
Correct |
214 ms |
30676 KB |
Output is correct |
22 |
Correct |
227 ms |
30804 KB |
Output is correct |
23 |
Correct |
247 ms |
30052 KB |
Output is correct |
24 |
Correct |
244 ms |
29488 KB |
Output is correct |
25 |
Correct |
234 ms |
31924 KB |
Output is correct |
26 |
Correct |
256 ms |
30156 KB |
Output is correct |
27 |
Correct |
280 ms |
30088 KB |
Output is correct |
28 |
Correct |
178 ms |
32460 KB |
Output is correct |
29 |
Correct |
208 ms |
28500 KB |
Output is correct |
30 |
Correct |
227 ms |
30800 KB |
Output is correct |
31 |
Correct |
241 ms |
30552 KB |
Output is correct |
32 |
Correct |
238 ms |
30544 KB |
Output is correct |
33 |
Correct |
236 ms |
29524 KB |
Output is correct |
34 |
Correct |
249 ms |
29520 KB |
Output is correct |
35 |
Correct |
280 ms |
30036 KB |
Output is correct |
36 |
Correct |
163 ms |
28752 KB |
Output is correct |
37 |
Correct |
216 ms |
30544 KB |
Output is correct |
38 |
Correct |
218 ms |
28864 KB |
Output is correct |
39 |
Correct |
247 ms |
29776 KB |
Output is correct |
40 |
Correct |
248 ms |
29524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
712 KB |
Output is correct |
11 |
Runtime error |
5 ms |
4092 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
856 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
712 KB |
Output is correct |
11 |
Correct |
162 ms |
15692 KB |
Output is correct |
12 |
Correct |
165 ms |
15324 KB |
Output is correct |
13 |
Correct |
175 ms |
14512 KB |
Output is correct |
14 |
Correct |
177 ms |
14588 KB |
Output is correct |
15 |
Correct |
171 ms |
15700 KB |
Output is correct |
16 |
Correct |
185 ms |
14676 KB |
Output is correct |
17 |
Correct |
188 ms |
14932 KB |
Output is correct |
18 |
Correct |
130 ms |
16468 KB |
Output is correct |
19 |
Correct |
149 ms |
13648 KB |
Output is correct |
20 |
Correct |
176 ms |
15208 KB |
Output is correct |
21 |
Correct |
214 ms |
30676 KB |
Output is correct |
22 |
Correct |
227 ms |
30804 KB |
Output is correct |
23 |
Correct |
247 ms |
30052 KB |
Output is correct |
24 |
Correct |
244 ms |
29488 KB |
Output is correct |
25 |
Correct |
234 ms |
31924 KB |
Output is correct |
26 |
Correct |
256 ms |
30156 KB |
Output is correct |
27 |
Correct |
280 ms |
30088 KB |
Output is correct |
28 |
Correct |
178 ms |
32460 KB |
Output is correct |
29 |
Correct |
208 ms |
28500 KB |
Output is correct |
30 |
Correct |
227 ms |
30800 KB |
Output is correct |
31 |
Correct |
241 ms |
30552 KB |
Output is correct |
32 |
Correct |
238 ms |
30544 KB |
Output is correct |
33 |
Correct |
236 ms |
29524 KB |
Output is correct |
34 |
Correct |
249 ms |
29520 KB |
Output is correct |
35 |
Correct |
280 ms |
30036 KB |
Output is correct |
36 |
Correct |
163 ms |
28752 KB |
Output is correct |
37 |
Correct |
216 ms |
30544 KB |
Output is correct |
38 |
Correct |
218 ms |
28864 KB |
Output is correct |
39 |
Correct |
247 ms |
29776 KB |
Output is correct |
40 |
Correct |
248 ms |
29524 KB |
Output is correct |
41 |
Runtime error |
5 ms |
4092 KB |
Execution killed with signal 6 |
42 |
Halted |
0 ms |
0 KB |
- |