# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
639847 | 2022-09-12T09:23:07 Z | danikoynov | JJOOII 2 (JOI20_ho_t2) | C++14 | 17 ms | 10740 KB |
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 2e5 + 10; int n, k, a[maxn], nxt[maxn][3], cur[maxn]; string s; vector < int > path[3]; void solve() { cin >> n >> k >> s; for (int i = 0; i < n; i ++) { if (s[i] == 'J') a[i + 1] = 0; else if (s[i] == 'O') a[i + 1] = 1; else a[i + 1] = 2; } int last0, last1, last2; last0 = last1 = last2 = n + 1; for (int i = n; i > 0; i --) { nxt[i][0] = last0; nxt[i][1] = last1; nxt[i][2] = last2; if (a[i] == 0) last0 = i; if (a[i] == 1) last1 = i; if (a[i] == 2) last2 = i; } for (int i = 1; i <= n; i ++) { cur[i] = path[a[i]].size(); path[a[i]].push_back(i); } while(path[0].size() < 2 * n) path[0].push_back(n + 1); while(path[1].size() < 2 * n) path[1].push_back(n + 1); while(path[2].size() < 2 * n) path[2].push_back(n + 1); int ans = 1e9; for (int i = 1; i <= n; i ++) { int pos = i; if (a[pos] != 0) pos = nxt[pos][0]; if (pos == n + 1) break; pos = path[a[pos]][cur[pos] + k - 1]; if (pos == n + 1) break; pos = nxt[pos][1]; if (pos == n + 1) break; pos = path[a[pos]][cur[pos] + k - 1]; if (pos == n + 1) break; pos = nxt[pos][2]; if (pos == n + 1) break; pos = path[a[pos]][cur[pos] + k - 1]; if (pos == n + 1) break; ans = min(ans, n - 3 * k - (i - 1) - (n - pos)); } if (ans == 1e9) cout << -1 << endl; else cout << ans << endl; } int main() { solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 220 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 220 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 1 ms | 468 KB | Output is correct |
17 | Correct | 1 ms | 468 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 432 KB | Output is correct |
21 | Correct | 1 ms | 468 KB | Output is correct |
22 | Correct | 1 ms | 432 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 432 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 1 ms | 436 KB | Output is correct |
29 | Correct | 1 ms | 468 KB | Output is correct |
30 | Correct | 1 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 468 KB | Output is correct |
33 | Correct | 1 ms | 468 KB | Output is correct |
34 | Correct | 1 ms | 468 KB | Output is correct |
35 | Correct | 1 ms | 468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 220 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 468 KB | Output is correct |
16 | Correct | 1 ms | 468 KB | Output is correct |
17 | Correct | 1 ms | 468 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 432 KB | Output is correct |
21 | Correct | 1 ms | 468 KB | Output is correct |
22 | Correct | 1 ms | 432 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 468 KB | Output is correct |
25 | Correct | 1 ms | 432 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 1 ms | 436 KB | Output is correct |
29 | Correct | 1 ms | 468 KB | Output is correct |
30 | Correct | 1 ms | 468 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 468 KB | Output is correct |
33 | Correct | 1 ms | 468 KB | Output is correct |
34 | Correct | 1 ms | 468 KB | Output is correct |
35 | Correct | 1 ms | 468 KB | Output is correct |
36 | Correct | 16 ms | 10180 KB | Output is correct |
37 | Correct | 17 ms | 10348 KB | Output is correct |
38 | Correct | 17 ms | 10284 KB | Output is correct |
39 | Correct | 17 ms | 10740 KB | Output is correct |
40 | Correct | 15 ms | 10280 KB | Output is correct |
41 | Correct | 16 ms | 10288 KB | Output is correct |
42 | Correct | 16 ms | 10336 KB | Output is correct |
43 | Correct | 10 ms | 6344 KB | Output is correct |
44 | Correct | 11 ms | 8776 KB | Output is correct |
45 | Correct | 15 ms | 10288 KB | Output is correct |
46 | Correct | 14 ms | 10292 KB | Output is correct |
47 | Correct | 15 ms | 10280 KB | Output is correct |
48 | Correct | 15 ms | 10276 KB | Output is correct |
49 | Correct | 10 ms | 7844 KB | Output is correct |
50 | Correct | 15 ms | 10312 KB | Output is correct |
51 | Correct | 16 ms | 10260 KB | Output is correct |
52 | Correct | 14 ms | 10436 KB | Output is correct |
53 | Correct | 15 ms | 10260 KB | Output is correct |
54 | Correct | 13 ms | 10324 KB | Output is correct |
55 | Correct | 12 ms | 10332 KB | Output is correct |
56 | Correct | 12 ms | 10360 KB | Output is correct |