Submission #1114680

# Submission time Handle Problem Language Result Execution time Memory
1114680 2024-11-19T11:12:26 Z AdamGS JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 5116 KB
#include <iostream>

using namespace std;

const int MAXN = 200001;

int n, k;

int prefi_J[MAXN];
int prefi_O[MAXN];
int prefi_I[MAXN];

int wystepowanie_J[MAXN];
int wystepowanie_O[MAXN];
int wystepowanie_I[MAXN]; //na jakim indeksie najwczesniej wystepuje wartosc i

char slowo[MAXN];

int zrob(int ktore_j) { //ile trzeba bedzie uzyc operacji 3 typu pesymistycznie zakładając ze pierwsze J w wyrazie bedzie ktore_j w calym wyrazie
	int aktl_ind = wystepowanie_J[ktore_j + k];
	int ile_O_przed = prefi_O[aktl_ind];
	aktl_ind++;
	if ((prefi_O[n] - ile_O_przed) < k) {
		return 1000000000;
	}
	int ktore_o = ile_O_przed + k;
	aktl_ind = wystepowanie_O[ktore_o];
	int ile_i_przed = prefi_I[aktl_ind];
	aktl_ind++;
	if ((prefi_I[n] - ile_i_przed) < k) {
		return 1000000000;
	}
	int ktore_i = ile_i_przed + k;
	aktl_ind = wystepowanie_I[ktore_i];
	int ile_liter = aktl_ind - (wystepowanie_J[ktore_j + 1] - 1);
	ile_liter -= (3 * k);
	return ile_liter;
}
	
	
int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	for (int i = 1; n >= i; i++) {
		cin >> slowo[i];
		prefi_J[i] = prefi_J[i - 1];
		prefi_I[i] = prefi_I[i - 1];
		prefi_O[i] = prefi_O[i - 1];
		if (slowo[i] == 'J') {
			prefi_J[i]++;
			wystepowanie_J[prefi_J[i]] = i;
		} else if (slowo[i] == 'O') {
			prefi_O[i]++;
			wystepowanie_O[prefi_O[i]] = i;
		} else {
			prefi_I[i]++;
			wystepowanie_I[prefi_I[i]] = i;
		}
	}
	
	if (prefi_J[n] < k) {
		cout << -1;
		return 0;
	}
	int wynik = 1000000000;
	for (int i = 0; (prefi_J[n] - k) >= i; i++) {
		wynik = min(wynik, zrob(i));
	}
	if (wynik == 1000000000) wynik = -1;
	cout << wynik;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 2 ms 2384 KB Output is correct
17 Correct 2 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2552 KB Output is correct
24 Correct 2 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 2 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2552 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 2 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 2 ms 2384 KB Output is correct
17 Correct 2 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2552 KB Output is correct
24 Correct 2 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 2 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2552 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 7 ms 4708 KB Output is correct
37 Correct 7 ms 5044 KB Output is correct
38 Correct 7 ms 4944 KB Output is correct
39 Correct 6 ms 4944 KB Output is correct
40 Correct 9 ms 4944 KB Output is correct
41 Correct 7 ms 5116 KB Output is correct
42 Correct 7 ms 4944 KB Output is correct
43 Correct 5 ms 3920 KB Output is correct
44 Correct 5 ms 4364 KB Output is correct
45 Correct 7 ms 4944 KB Output is correct
46 Correct 6 ms 4944 KB Output is correct
47 Correct 8 ms 4944 KB Output is correct
48 Correct 6 ms 4944 KB Output is correct
49 Correct 5 ms 4344 KB Output is correct
50 Correct 6 ms 4944 KB Output is correct
51 Correct 7 ms 4944 KB Output is correct
52 Correct 6 ms 4944 KB Output is correct
53 Correct 7 ms 4812 KB Output is correct
54 Correct 4 ms 5112 KB Output is correct
55 Correct 5 ms 4944 KB Output is correct
56 Correct 5 ms 4944 KB Output is correct