#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
const char el = '\n';
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int n, k; cin >> n >> k;
string s; cin >> s;
vector<int> J, O, I;
for(int i=0; i<n; i++)
switch(s[i]) {
case 'J': J.push_back(i); break;
case 'O': O.push_back(i); break;
case 'I': I.push_back(i); break;
}
int ij = 0, io = 0, ii = 0, jsz = J.size(), osz = O.size(), isz = I.size();
int endj, endo, sol = INT_MAX;
auto print_sol = [&] () {
if(sol==INT_MAX) cout << -1 << el;
else cout << sol << el;
return 0;
};
while(true) {
if(ij+k-1>=jsz) return print_sol();
endj = J[ij+k-1];
while(io<osz && O[io]<=endj) io++;
if(io+k-1>=osz) return print_sol();
endo = O[io+k-1];
while(ii<isz && I[ii]<=endo) ii++;
if(ii+k-1>=isz) return print_sol();
sol = min(sol, I[ii+k-1]-J[ij]+1-k-k-k);
ij++;
}
return print_sol();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
1744 KB |
Output is correct |
37 |
Correct |
4 ms |
1824 KB |
Output is correct |
38 |
Correct |
4 ms |
1964 KB |
Output is correct |
39 |
Correct |
4 ms |
1988 KB |
Output is correct |
40 |
Correct |
3 ms |
1996 KB |
Output is correct |
41 |
Correct |
4 ms |
1924 KB |
Output is correct |
42 |
Correct |
4 ms |
1824 KB |
Output is correct |
43 |
Correct |
2 ms |
1268 KB |
Output is correct |
44 |
Correct |
2 ms |
1496 KB |
Output is correct |
45 |
Correct |
3 ms |
2008 KB |
Output is correct |
46 |
Correct |
3 ms |
2008 KB |
Output is correct |
47 |
Correct |
3 ms |
2008 KB |
Output is correct |
48 |
Correct |
3 ms |
2008 KB |
Output is correct |
49 |
Correct |
2 ms |
1336 KB |
Output is correct |
50 |
Correct |
3 ms |
1968 KB |
Output is correct |
51 |
Correct |
3 ms |
2008 KB |
Output is correct |
52 |
Correct |
3 ms |
1488 KB |
Output is correct |
53 |
Correct |
3 ms |
1732 KB |
Output is correct |
54 |
Correct |
2 ms |
2012 KB |
Output is correct |
55 |
Correct |
3 ms |
2000 KB |
Output is correct |
56 |
Correct |
2 ms |
1988 KB |
Output is correct |