#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int N, K;
string str;
int main() {
cin >> N >> K >> str;
vector<int> J, O, I;
for (int i = 0; i < (int)str.size(); i++) {
if (str[i] == 'J') {
J.push_back(i+1);
}
else if (str[i] == 'O') {
O.push_back(i+1);
}
else {
I.push_back(i+1);
}
}
vector<int> A[2], B[2], C[2];
for (int i = 0; i+K-1 < (int)J.size(); i++) {
A[0].push_back(J[i]);
A[1].push_back(J[K+i-1]);
}
for (int i = 0; i+K-1 < (int)O.size(); i++) {
B[0].push_back(O[i]);
B[1].push_back(O[K+i-1]);
}
for (int i = 0; i+K-1 < (int)I.size(); i++) {
C[0].push_back(I[i]);
C[1].push_back(I[K+i-1]);
}
int ans = INT_MAX;
for (int a = 0; a < (int)A[0].size(); a++) {
if (upper_bound(B[0].begin(), B[0].end(), A[1][a]) == B[0].end()) break;
int b = upper_bound(B[0].begin(), B[0].end(), A[1][a])-B[0].begin();
if (upper_bound(C[0].begin(), C[0].end(), B[1][b]) == C[0].end()) break;
int c = upper_bound(C[0].begin(), C[0].end(), B[1][b])-C[0].begin();
ans = min(ans, C[1][c]-A[0][a]-3*K+1);
}
if (ans == INT_MAX) ans = -1;
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
292 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
300 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
292 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
300 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
14 ms |
3040 KB |
Output is correct |
37 |
Correct |
19 ms |
4244 KB |
Output is correct |
38 |
Correct |
15 ms |
4068 KB |
Output is correct |
39 |
Correct |
14 ms |
3228 KB |
Output is correct |
40 |
Correct |
8 ms |
2992 KB |
Output is correct |
41 |
Correct |
12 ms |
3216 KB |
Output is correct |
42 |
Correct |
15 ms |
4120 KB |
Output is correct |
43 |
Correct |
4 ms |
1880 KB |
Output is correct |
44 |
Correct |
4 ms |
2232 KB |
Output is correct |
45 |
Correct |
6 ms |
2896 KB |
Output is correct |
46 |
Correct |
6 ms |
2884 KB |
Output is correct |
47 |
Correct |
6 ms |
2860 KB |
Output is correct |
48 |
Correct |
6 ms |
2892 KB |
Output is correct |
49 |
Correct |
4 ms |
1976 KB |
Output is correct |
50 |
Correct |
6 ms |
2772 KB |
Output is correct |
51 |
Correct |
6 ms |
2872 KB |
Output is correct |
52 |
Correct |
5 ms |
1752 KB |
Output is correct |
53 |
Correct |
5 ms |
1828 KB |
Output is correct |
54 |
Correct |
9 ms |
4068 KB |
Output is correct |
55 |
Correct |
8 ms |
2320 KB |
Output is correct |
56 |
Correct |
4 ms |
1888 KB |
Output is correct |