# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201034 | 2020-02-09T06:38:53 Z | HellAngel | JJOOII 2 (JOI20_ho_t2) | C++14 | 94 ms | 48516 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 200007; string s; int nxt[20][maxn][3], a[maxn], n, k, ans; void Jump(int &pos, int type, int cnt) { for(int i = 19; i >= 0; i--) { if(cnt >= (1 << i)) { cnt -= (1 << i); pos = nxt[i][pos][type]; } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin); cin >> n >> k >> s; ans = n + 1; for(int i = 1; i <= n; i++) { if(s[i - 1] == 'J') a[i] = 0; if(s[i - 1] == 'O') a[i] = 1; if(s[i - 1] == 'I') a[i] = 2; } nxt[0][n + 1][0] = nxt[0][n + 1][1] = nxt[0][n + 1][2] = n + 1; for(int i = n; i >= 1; i--) { for(int j = 0; j < 3; j++) nxt[0][i][j] = nxt[0][i + 1][j]; if(i == n) continue; nxt[0][i][a[i + 1]] = i + 1; } for(int len = 1; len < 20; len++) { for(int i = 1; i <= n + 1; i++) { for(int j = 0; j < 3; j++) { int nlen = (1 << len); if(i + nlen - 1 > n) nxt[len][i][j] = 1 + n; nxt[len][i][j] = nxt[len - 1][nxt[len - 1][i][j]][j]; } } } for(int i = 1; i <= n; i++) { int cur = i; if(a[cur] != 0) continue; Jump(cur, 0, k - 1); Jump(cur, 1, k); Jump(cur, 2, k); if(cur <= n) { ans = min(ans, cur - i + 1 - k * 3); } } if(ans == n + 1) cout << -1; else cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 504 KB | Output is correct |
2 | Correct | 5 ms | 504 KB | Output is correct |
3 | Correct | 5 ms | 504 KB | Output is correct |
4 | Correct | 5 ms | 504 KB | Output is correct |
5 | Correct | 5 ms | 504 KB | Output is correct |
6 | Correct | 5 ms | 504 KB | Output is correct |
7 | Correct | 5 ms | 504 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 504 KB | Output is correct |
10 | Correct | 5 ms | 504 KB | Output is correct |
11 | Correct | 5 ms | 504 KB | Output is correct |
12 | Correct | 5 ms | 504 KB | Output is correct |
13 | Correct | 5 ms | 504 KB | Output is correct |
14 | Correct | 5 ms | 504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 504 KB | Output is correct |
2 | Correct | 5 ms | 504 KB | Output is correct |
3 | Correct | 5 ms | 504 KB | Output is correct |
4 | Correct | 5 ms | 504 KB | Output is correct |
5 | Correct | 5 ms | 504 KB | Output is correct |
6 | Correct | 5 ms | 504 KB | Output is correct |
7 | Correct | 5 ms | 504 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 504 KB | Output is correct |
10 | Correct | 5 ms | 504 KB | Output is correct |
11 | Correct | 5 ms | 504 KB | Output is correct |
12 | Correct | 5 ms | 504 KB | Output is correct |
13 | Correct | 5 ms | 504 KB | Output is correct |
14 | Correct | 5 ms | 504 KB | Output is correct |
15 | Correct | 5 ms | 1144 KB | Output is correct |
16 | Correct | 6 ms | 1144 KB | Output is correct |
17 | Correct | 6 ms | 1272 KB | Output is correct |
18 | Correct | 5 ms | 888 KB | Output is correct |
19 | Correct | 5 ms | 1144 KB | Output is correct |
20 | Correct | 6 ms | 1144 KB | Output is correct |
21 | Correct | 6 ms | 1144 KB | Output is correct |
22 | Correct | 5 ms | 1144 KB | Output is correct |
23 | Correct | 5 ms | 888 KB | Output is correct |
24 | Correct | 5 ms | 1144 KB | Output is correct |
25 | Correct | 6 ms | 1148 KB | Output is correct |
26 | Correct | 5 ms | 1276 KB | Output is correct |
27 | Correct | 5 ms | 1144 KB | Output is correct |
28 | Correct | 6 ms | 1272 KB | Output is correct |
29 | Correct | 8 ms | 1272 KB | Output is correct |
30 | Correct | 5 ms | 1144 KB | Output is correct |
31 | Correct | 5 ms | 760 KB | Output is correct |
32 | Correct | 5 ms | 1148 KB | Output is correct |
33 | Correct | 6 ms | 1272 KB | Output is correct |
34 | Correct | 6 ms | 1144 KB | Output is correct |
35 | Correct | 5 ms | 1144 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 504 KB | Output is correct |
2 | Correct | 5 ms | 504 KB | Output is correct |
3 | Correct | 5 ms | 504 KB | Output is correct |
4 | Correct | 5 ms | 504 KB | Output is correct |
5 | Correct | 5 ms | 504 KB | Output is correct |
6 | Correct | 5 ms | 504 KB | Output is correct |
7 | Correct | 5 ms | 504 KB | Output is correct |
8 | Correct | 5 ms | 504 KB | Output is correct |
9 | Correct | 5 ms | 504 KB | Output is correct |
10 | Correct | 5 ms | 504 KB | Output is correct |
11 | Correct | 5 ms | 504 KB | Output is correct |
12 | Correct | 5 ms | 504 KB | Output is correct |
13 | Correct | 5 ms | 504 KB | Output is correct |
14 | Correct | 5 ms | 504 KB | Output is correct |
15 | Correct | 5 ms | 1144 KB | Output is correct |
16 | Correct | 6 ms | 1144 KB | Output is correct |
17 | Correct | 6 ms | 1272 KB | Output is correct |
18 | Correct | 5 ms | 888 KB | Output is correct |
19 | Correct | 5 ms | 1144 KB | Output is correct |
20 | Correct | 6 ms | 1144 KB | Output is correct |
21 | Correct | 6 ms | 1144 KB | Output is correct |
22 | Correct | 5 ms | 1144 KB | Output is correct |
23 | Correct | 5 ms | 888 KB | Output is correct |
24 | Correct | 5 ms | 1144 KB | Output is correct |
25 | Correct | 6 ms | 1148 KB | Output is correct |
26 | Correct | 5 ms | 1276 KB | Output is correct |
27 | Correct | 5 ms | 1144 KB | Output is correct |
28 | Correct | 6 ms | 1272 KB | Output is correct |
29 | Correct | 8 ms | 1272 KB | Output is correct |
30 | Correct | 5 ms | 1144 KB | Output is correct |
31 | Correct | 5 ms | 760 KB | Output is correct |
32 | Correct | 5 ms | 1148 KB | Output is correct |
33 | Correct | 6 ms | 1272 KB | Output is correct |
34 | Correct | 6 ms | 1144 KB | Output is correct |
35 | Correct | 5 ms | 1144 KB | Output is correct |
36 | Correct | 54 ms | 45316 KB | Output is correct |
37 | Correct | 54 ms | 48388 KB | Output is correct |
38 | Correct | 54 ms | 48388 KB | Output is correct |
39 | Correct | 54 ms | 48004 KB | Output is correct |
40 | Correct | 55 ms | 48388 KB | Output is correct |
41 | Correct | 56 ms | 48388 KB | Output is correct |
42 | Correct | 54 ms | 48388 KB | Output is correct |
43 | Correct | 35 ms | 30328 KB | Output is correct |
44 | Correct | 41 ms | 37636 KB | Output is correct |
45 | Correct | 54 ms | 48388 KB | Output is correct |
46 | Correct | 55 ms | 48388 KB | Output is correct |
47 | Correct | 56 ms | 48388 KB | Output is correct |
48 | Correct | 56 ms | 48516 KB | Output is correct |
49 | Correct | 38 ms | 32516 KB | Output is correct |
50 | Correct | 55 ms | 48384 KB | Output is correct |
51 | Correct | 94 ms | 48388 KB | Output is correct |
52 | Correct | 53 ms | 46596 KB | Output is correct |
53 | Correct | 57 ms | 48388 KB | Output is correct |
54 | Correct | 54 ms | 48388 KB | Output is correct |
55 | Correct | 52 ms | 48388 KB | Output is correct |
56 | Correct | 54 ms | 48388 KB | Output is correct |