Submission #680579

# Submission time Handle Problem Language Result Execution time Memory
680579 2023-01-11T10:02:29 Z ethening JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
20 ms 11860 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int c2i(char c) {
	if (c == 'J') return 0;
	else if (c == 'O') return 1;
	else return 2;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, k;
	string s;

	cin >> n >> k;
	vector p = vector(n + 5, vector<int>(3, 0));
	cin >> s;

	for (int i = 0; i < n; i++) {
		if (i > 0) {
			for (int k = 0; k < 3; k++) {
				p[i][k] = p[i - 1][k];
			}
		}
		++p[i][c2i(s[i])];
	}

	auto rge_sum = [&](int l, int r, char c) {
		int ret = p[r][c2i(c)];
		if (l > 0) {
			ret -= p[l - 1][c2i(c)];
		}
		return ret;
	};

	int ans = -1;
	int jen = 0;
	int oen = 0;
	int ien = 0;
	for (int i = 0; i < n; i++) {
		if (jen < i) jen = i;
		while (jen < n && rge_sum(i, jen, 'J') < k) {
			++jen;
		}
		if (jen == n && rge_sum(i, jen, 'J') < k) break;

		if (oen <= jen) oen = jen + 1;
		while (oen < n && rge_sum(jen + 1, oen, 'O') < k) {
			++oen;
		}
		if (oen == n && rge_sum(jen + 1, oen, 'O') < k) break;

		if (ien <= oen) ien = oen + 1;
		while (ien < n && rge_sum(oen + 1, ien, 'I') < k) {
			++ien;
		}
		if (ien == n && rge_sum(oen + 1, ien, 'I') < k) break;
		
		int cost = ien - i + 1 - 3 * k;
		if (ans == -1 || cost < ans) ans = cost;
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 236 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 1 ms 364 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 236 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 1 ms 364 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 448 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 452 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 444 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 468 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 468 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 448 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 236 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 316 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 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 1 ms 364 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 448 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 452 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 444 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 468 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 468 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 448 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 10972 KB Output is correct
37 Correct 17 ms 11856 KB Output is correct
38 Correct 17 ms 11836 KB Output is correct
39 Correct 19 ms 11708 KB Output is correct
40 Correct 17 ms 11848 KB Output is correct
41 Correct 18 ms 11740 KB Output is correct
42 Correct 19 ms 11800 KB Output is correct
43 Correct 11 ms 7380 KB Output is correct
44 Correct 11 ms 9292 KB Output is correct
45 Correct 16 ms 11832 KB Output is correct
46 Correct 15 ms 11844 KB Output is correct
47 Correct 15 ms 11776 KB Output is correct
48 Correct 15 ms 11784 KB Output is correct
49 Correct 11 ms 8020 KB Output is correct
50 Correct 20 ms 11844 KB Output is correct
51 Correct 16 ms 11860 KB Output is correct
52 Correct 19 ms 11420 KB Output is correct
53 Correct 14 ms 11792 KB Output is correct
54 Correct 14 ms 11780 KB Output is correct
55 Correct 14 ms 11840 KB Output is correct
56 Correct 15 ms 11860 KB Output is correct