# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
868839 |
2023-11-02T05:11:54 Z |
mzh |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
29 ms |
43240 KB |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 2e5 + 5, LG = __lg(MXN) + 1;
int jmp[3][LG][MXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
string s;
cin >> n >> m >> s;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < LG; j++) {
for (int k = 0; k <= n + 1; k++) {
jmp[i][j][k] = n + 1;
}
}
}
for (int i = 0; i < 3; i++) {
for (int j = n - 1; j >= 0; j--) {
jmp[i][0][j] = (s[j] == "JOI"[i] ? j + 1 : jmp[i][0][j + 1]);
}
for (int j = 1; j < LG; j++) {
for (int k = 0; k + (1 << j) <= n; k++) {
jmp[i][j][k] = jmp[i][j - 1][jmp[i][j - 1][k]];
}
}
}
int ans = 1e9;
for (int i = 0; i < n; i++) {
int idx = i;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < LG; k++) {
if ((m >> k) & 1) {
idx = jmp[j][k][idx];
}
}
}
if (idx != n + 1) {
ans = min(ans, idx - i - 3 * m);
}
}
cout << (ans == 1e9 ? -1 : ans) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
41308 KB |
Output is correct |
2 |
Correct |
4 ms |
41308 KB |
Output is correct |
3 |
Correct |
4 ms |
41308 KB |
Output is correct |
4 |
Correct |
4 ms |
41308 KB |
Output is correct |
5 |
Correct |
4 ms |
41308 KB |
Output is correct |
6 |
Correct |
4 ms |
41308 KB |
Output is correct |
7 |
Correct |
5 ms |
41308 KB |
Output is correct |
8 |
Correct |
4 ms |
41308 KB |
Output is correct |
9 |
Correct |
4 ms |
41308 KB |
Output is correct |
10 |
Correct |
4 ms |
41308 KB |
Output is correct |
11 |
Correct |
4 ms |
41432 KB |
Output is correct |
12 |
Correct |
4 ms |
41308 KB |
Output is correct |
13 |
Correct |
4 ms |
41496 KB |
Output is correct |
14 |
Correct |
4 ms |
41308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
41308 KB |
Output is correct |
2 |
Correct |
4 ms |
41308 KB |
Output is correct |
3 |
Correct |
4 ms |
41308 KB |
Output is correct |
4 |
Correct |
4 ms |
41308 KB |
Output is correct |
5 |
Correct |
4 ms |
41308 KB |
Output is correct |
6 |
Correct |
4 ms |
41308 KB |
Output is correct |
7 |
Correct |
5 ms |
41308 KB |
Output is correct |
8 |
Correct |
4 ms |
41308 KB |
Output is correct |
9 |
Correct |
4 ms |
41308 KB |
Output is correct |
10 |
Correct |
4 ms |
41308 KB |
Output is correct |
11 |
Correct |
4 ms |
41432 KB |
Output is correct |
12 |
Correct |
4 ms |
41308 KB |
Output is correct |
13 |
Correct |
4 ms |
41496 KB |
Output is correct |
14 |
Correct |
4 ms |
41308 KB |
Output is correct |
15 |
Correct |
5 ms |
41308 KB |
Output is correct |
16 |
Correct |
5 ms |
41308 KB |
Output is correct |
17 |
Correct |
5 ms |
41304 KB |
Output is correct |
18 |
Correct |
4 ms |
41308 KB |
Output is correct |
19 |
Correct |
5 ms |
41308 KB |
Output is correct |
20 |
Correct |
5 ms |
41308 KB |
Output is correct |
21 |
Correct |
5 ms |
41308 KB |
Output is correct |
22 |
Correct |
6 ms |
41308 KB |
Output is correct |
23 |
Correct |
6 ms |
41304 KB |
Output is correct |
24 |
Correct |
5 ms |
41308 KB |
Output is correct |
25 |
Correct |
5 ms |
41452 KB |
Output is correct |
26 |
Correct |
5 ms |
41304 KB |
Output is correct |
27 |
Correct |
5 ms |
41308 KB |
Output is correct |
28 |
Correct |
5 ms |
41424 KB |
Output is correct |
29 |
Correct |
4 ms |
41308 KB |
Output is correct |
30 |
Correct |
5 ms |
41308 KB |
Output is correct |
31 |
Correct |
4 ms |
41308 KB |
Output is correct |
32 |
Correct |
5 ms |
41500 KB |
Output is correct |
33 |
Correct |
5 ms |
41308 KB |
Output is correct |
34 |
Correct |
4 ms |
41304 KB |
Output is correct |
35 |
Correct |
5 ms |
41308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
41308 KB |
Output is correct |
2 |
Correct |
4 ms |
41308 KB |
Output is correct |
3 |
Correct |
4 ms |
41308 KB |
Output is correct |
4 |
Correct |
4 ms |
41308 KB |
Output is correct |
5 |
Correct |
4 ms |
41308 KB |
Output is correct |
6 |
Correct |
4 ms |
41308 KB |
Output is correct |
7 |
Correct |
5 ms |
41308 KB |
Output is correct |
8 |
Correct |
4 ms |
41308 KB |
Output is correct |
9 |
Correct |
4 ms |
41308 KB |
Output is correct |
10 |
Correct |
4 ms |
41308 KB |
Output is correct |
11 |
Correct |
4 ms |
41432 KB |
Output is correct |
12 |
Correct |
4 ms |
41308 KB |
Output is correct |
13 |
Correct |
4 ms |
41496 KB |
Output is correct |
14 |
Correct |
4 ms |
41308 KB |
Output is correct |
15 |
Correct |
5 ms |
41308 KB |
Output is correct |
16 |
Correct |
5 ms |
41308 KB |
Output is correct |
17 |
Correct |
5 ms |
41304 KB |
Output is correct |
18 |
Correct |
4 ms |
41308 KB |
Output is correct |
19 |
Correct |
5 ms |
41308 KB |
Output is correct |
20 |
Correct |
5 ms |
41308 KB |
Output is correct |
21 |
Correct |
5 ms |
41308 KB |
Output is correct |
22 |
Correct |
6 ms |
41308 KB |
Output is correct |
23 |
Correct |
6 ms |
41304 KB |
Output is correct |
24 |
Correct |
5 ms |
41308 KB |
Output is correct |
25 |
Correct |
5 ms |
41452 KB |
Output is correct |
26 |
Correct |
5 ms |
41304 KB |
Output is correct |
27 |
Correct |
5 ms |
41308 KB |
Output is correct |
28 |
Correct |
5 ms |
41424 KB |
Output is correct |
29 |
Correct |
4 ms |
41308 KB |
Output is correct |
30 |
Correct |
5 ms |
41308 KB |
Output is correct |
31 |
Correct |
4 ms |
41308 KB |
Output is correct |
32 |
Correct |
5 ms |
41500 KB |
Output is correct |
33 |
Correct |
5 ms |
41308 KB |
Output is correct |
34 |
Correct |
4 ms |
41304 KB |
Output is correct |
35 |
Correct |
5 ms |
41308 KB |
Output is correct |
36 |
Correct |
23 ms |
42984 KB |
Output is correct |
37 |
Correct |
25 ms |
43240 KB |
Output is correct |
38 |
Correct |
29 ms |
43176 KB |
Output is correct |
39 |
Correct |
26 ms |
43240 KB |
Output is correct |
40 |
Correct |
27 ms |
43236 KB |
Output is correct |
41 |
Correct |
28 ms |
43240 KB |
Output is correct |
42 |
Correct |
26 ms |
43236 KB |
Output is correct |
43 |
Correct |
17 ms |
42328 KB |
Output is correct |
44 |
Correct |
21 ms |
42728 KB |
Output is correct |
45 |
Correct |
27 ms |
43240 KB |
Output is correct |
46 |
Correct |
28 ms |
43240 KB |
Output is correct |
47 |
Correct |
27 ms |
43236 KB |
Output is correct |
48 |
Correct |
28 ms |
43240 KB |
Output is correct |
49 |
Correct |
18 ms |
42468 KB |
Output is correct |
50 |
Correct |
26 ms |
43240 KB |
Output is correct |
51 |
Correct |
29 ms |
43240 KB |
Output is correct |
52 |
Correct |
25 ms |
42984 KB |
Output is correct |
53 |
Correct |
28 ms |
43240 KB |
Output is correct |
54 |
Correct |
23 ms |
43240 KB |
Output is correct |
55 |
Correct |
29 ms |
43240 KB |
Output is correct |
56 |
Correct |
26 ms |
43236 KB |
Output is correct |