#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> preJ(n, 0), preO(n, 0), preI(n, 0);
preJ[0] = (s[0] == 'J');
preO[0] = (s[0] == 'O');
preI[0] = (s[0] == 'I');
for (int i = 1; i < n; i++)
{
preJ[i] = preJ[i - 1] + (s[i] == 'J');
preO[i] = preO[i - 1] + (s[i] == 'O');
preI[i] = preI[i - 1] + (s[i] == 'I');
}
int ans = n + 1;
for (int i = 0; i < n; i++)
{
int x = lower_bound(preJ.begin(), preJ.end(), i + 1) - preJ.begin();
int J = lower_bound(preJ.begin(), preJ.end(), i + k) - preJ.begin();
if (J >= n)
continue;
int O = lower_bound(preO.begin(), preO.end(), preO[J] + k) - preO.begin();
if (O >= n)
continue;
int I = lower_bound(preI.begin(), preI.end(), preI[O] + k) - preI.begin();
if (I >= n)
continue;
ans = min(ans, I - x + 1 - 3 * k);
}
cout << (ans == n + 1 ? -1 : ans) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
440 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
440 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
440 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
440 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
22 ms |
3052 KB |
Output is correct |
37 |
Correct |
21 ms |
3308 KB |
Output is correct |
38 |
Correct |
23 ms |
3308 KB |
Output is correct |
39 |
Correct |
24 ms |
3308 KB |
Output is correct |
40 |
Correct |
21 ms |
3312 KB |
Output is correct |
41 |
Correct |
22 ms |
3308 KB |
Output is correct |
42 |
Correct |
26 ms |
3312 KB |
Output is correct |
43 |
Correct |
14 ms |
2284 KB |
Output is correct |
44 |
Correct |
16 ms |
2536 KB |
Output is correct |
45 |
Correct |
21 ms |
3308 KB |
Output is correct |
46 |
Correct |
20 ms |
3308 KB |
Output is correct |
47 |
Correct |
18 ms |
3504 KB |
Output is correct |
48 |
Correct |
20 ms |
3304 KB |
Output is correct |
49 |
Correct |
14 ms |
2284 KB |
Output is correct |
50 |
Correct |
20 ms |
3308 KB |
Output is correct |
51 |
Correct |
18 ms |
3308 KB |
Output is correct |
52 |
Correct |
17 ms |
3052 KB |
Output is correct |
53 |
Correct |
16 ms |
3560 KB |
Output is correct |
54 |
Correct |
19 ms |
3304 KB |
Output is correct |
55 |
Correct |
18 ms |
3308 KB |
Output is correct |
56 |
Correct |
17 ms |
3316 KB |
Output is correct |