#include <bits/stdc++.h>
#define MN 200071
using namespace std;
int n, k, F[3][MN];
inline int id (char c) {
return c == 'I' ? 2 : c == 'O';
}
int solve(int p1) {
int len = n - p1 + 1;
int st = p1, dr = n, mij;
for(int cul = 0; cul < 3; ++cul) {
if(F[cul][n] - F[cul][p1-1] < k) return -1;
st = p1, dr = n;
while(st < dr) {
mij = (st + dr) >> 1;
if(F[cul][mij] - F[cul][p1-1] >= k) dr = mij;
else st = mij + 1;
}
p1 = st + 1;
}
return len - (n - p1 + 1) - 3 * k;
}
string S;
int main() {
cin >> n >> k >> S;
for(int i = 1; i <= n; ++i) {
++F[id(S[i-1])][i];
for(int d = 0; d < 3; ++d) F[d][i] += F[d][i-1];
}
int rez = -1, ac = 0;
for(int i = 1; i <= n; ++i) {
ac = solve(i);
if(ac != -1) {
if(rez == -1) rez = ac;
else rez = min(rez, ac);
}
}
cout << rez << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 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 |
304 KB |
Output is correct |
28 |
Correct |
1 ms |
340 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 |
312 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 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 |
304 KB |
Output is correct |
28 |
Correct |
1 ms |
340 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 |
312 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
23 ms |
2916 KB |
Output is correct |
37 |
Correct |
26 ms |
3152 KB |
Output is correct |
38 |
Correct |
25 ms |
3172 KB |
Output is correct |
39 |
Correct |
35 ms |
3044 KB |
Output is correct |
40 |
Correct |
21 ms |
3172 KB |
Output is correct |
41 |
Correct |
30 ms |
3156 KB |
Output is correct |
42 |
Correct |
39 ms |
3048 KB |
Output is correct |
43 |
Correct |
12 ms |
2048 KB |
Output is correct |
44 |
Correct |
13 ms |
2532 KB |
Output is correct |
45 |
Correct |
18 ms |
3172 KB |
Output is correct |
46 |
Correct |
17 ms |
3052 KB |
Output is correct |
47 |
Correct |
17 ms |
3172 KB |
Output is correct |
48 |
Correct |
17 ms |
3172 KB |
Output is correct |
49 |
Correct |
13 ms |
2252 KB |
Output is correct |
50 |
Correct |
17 ms |
3172 KB |
Output is correct |
51 |
Correct |
20 ms |
3144 KB |
Output is correct |
52 |
Correct |
9 ms |
3020 KB |
Output is correct |
53 |
Correct |
10 ms |
3124 KB |
Output is correct |
54 |
Correct |
14 ms |
3148 KB |
Output is correct |
55 |
Correct |
11 ms |
3076 KB |
Output is correct |
56 |
Correct |
7 ms |
3056 KB |
Output is correct |