# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
242676 | 2020-06-28T23:18:45 Z | fishy15 | JJOOII 2 (JOI20_ho_t2) | C++14 | 15 ms | 4748 KB |
#include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <array> #include <algorithm> #include <utility> #include <map> #include <queue> #include <set> #include <cmath> #define ll long long #define eps 1e-8 #define MOD 1000000007 #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3f // change if necessary #define MAXN 200010 using namespace std; int n, k; string s; int dp[MAXN][3]; int jrem[MAXN]; int irem[MAXN]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; cin >> s; for (int i = 1; i <= n; i++) { switch (s[i - 1]) { case 'J': dp[i][0]++; break; case 'O': dp[i][1]++; break; case 'I': dp[i][2]++; break; } dp[i][0] += dp[i - 1][0]; dp[i][1] += dp[i - 1][1]; dp[i][2] += dp[i - 1][2]; } queue<int> j; for (int i = 1; i <= n; i++) { if (s[i - 1] == 'J') { j.push(i); if (j.size() > k) j.pop(); } if (j.size() == k) jrem[i] = j.front(); } queue<int> ii; for (int i = n; i >= 1; i--) { if (s[i - 1] == 'I') { ii.push(i); if (ii.size() > k) ii.pop(); } if (ii.size() == k) irem[i] = ii.front(); } int l = 1; int r = 1; int ans = INF; while (l <= n) { while (l <= n && !jrem[l]) { l++; if (r < l) r++; } while (r <= n && dp[r][1] - dp[l][1] < k) r++; if (!irem[r + 1]) break; ans = min(ans, n - 3 * k - jrem[l] + 1 - (n - irem[r + 1])); l++; } if (ans == INF) { cout << "-1\n"; } else { cout << ans << '\n'; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 432 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 432 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 384 KB | Output is correct |
6 | Correct | 5 ms | 384 KB | Output is correct |
7 | Correct | 5 ms | 384 KB | Output is correct |
8 | Correct | 5 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 384 KB | Output is correct |
10 | Correct | 5 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 384 KB | Output is correct |
12 | Correct | 5 ms | 432 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 5 ms | 384 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 5 ms | 384 KB | Output is correct |
18 | Correct | 5 ms | 384 KB | Output is correct |
19 | Correct | 5 ms | 384 KB | Output is correct |
20 | Correct | 5 ms | 384 KB | Output is correct |
21 | Correct | 5 ms | 384 KB | Output is correct |
22 | Correct | 5 ms | 384 KB | Output is correct |
23 | Correct | 5 ms | 384 KB | Output is correct |
24 | Correct | 5 ms | 384 KB | Output is correct |
25 | Correct | 5 ms | 384 KB | Output is correct |
26 | Correct | 5 ms | 384 KB | Output is correct |
27 | Correct | 5 ms | 384 KB | Output is correct |
28 | Correct | 5 ms | 384 KB | Output is correct |
29 | Correct | 5 ms | 384 KB | Output is correct |
30 | Correct | 5 ms | 384 KB | Output is correct |
31 | Correct | 5 ms | 384 KB | Output is correct |
32 | Correct | 5 ms | 384 KB | Output is correct |
33 | Correct | 5 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 5 ms | 384 KB | Output is correct |
36 | Correct | 13 ms | 4492 KB | Output is correct |
37 | Correct | 14 ms | 4748 KB | Output is correct |
38 | Correct | 14 ms | 4748 KB | Output is correct |
39 | Correct | 15 ms | 4620 KB | Output is correct |
40 | Correct | 12 ms | 4364 KB | Output is correct |
41 | Correct | 14 ms | 4620 KB | Output is correct |
42 | Correct | 14 ms | 4748 KB | Output is correct |
43 | Correct | 9 ms | 2816 KB | Output is correct |
44 | Correct | 11 ms | 3468 KB | Output is correct |
45 | Correct | 13 ms | 4492 KB | Output is correct |
46 | Correct | 13 ms | 4364 KB | Output is correct |
47 | Correct | 12 ms | 4364 KB | Output is correct |
48 | Correct | 14 ms | 4364 KB | Output is correct |
49 | Correct | 10 ms | 2956 KB | Output is correct |
50 | Correct | 13 ms | 4364 KB | Output is correct |
51 | Correct | 12 ms | 4364 KB | Output is correct |
52 | Correct | 12 ms | 3724 KB | Output is correct |
53 | Correct | 13 ms | 3852 KB | Output is correct |
54 | Correct | 10 ms | 4748 KB | Output is correct |
55 | Correct | 10 ms | 4748 KB | Output is correct |
56 | Correct | 10 ms | 4748 KB | Output is correct |