from bisect import *
from math import *
n,k = map(int, input().split())
s = input()
pref1 = [int(s[0]=="J")]
pref2 = [int(s[0]=="O")]
pref3 = [int(s[0]=="I")]
for i in range(1,n):
pref1.append(pref1[-1]+(s[i]=="J"))
pref2.append(pref2[-1]+(s[i]=="O"))
pref3.append(pref3[-1]+(s[i]=="I"))
ans = n+1
for i in range(n):
p = bisect_left(pref1,i+1)
a = bisect_left(pref1,i+k)
if a>=n:continue
b = bisect_left(pref2, pref2[a]+k)
if b>=n:continue
c = bisect_left(pref3, pref3[b]+k)
if c>=n:continue
ans = min(ans, c-p+1-3*k)
print(-1 if ans==n+1 else ans)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
18180 KB |
Output is correct |
2 |
Correct |
35 ms |
18260 KB |
Output is correct |
3 |
Correct |
33 ms |
18204 KB |
Output is correct |
4 |
Correct |
33 ms |
18204 KB |
Output is correct |
5 |
Correct |
33 ms |
18220 KB |
Output is correct |
6 |
Correct |
34 ms |
18240 KB |
Output is correct |
7 |
Correct |
37 ms |
18228 KB |
Output is correct |
8 |
Correct |
37 ms |
18252 KB |
Output is correct |
9 |
Correct |
38 ms |
18252 KB |
Output is correct |
10 |
Correct |
45 ms |
18260 KB |
Output is correct |
11 |
Correct |
34 ms |
18172 KB |
Output is correct |
12 |
Correct |
34 ms |
18228 KB |
Output is correct |
13 |
Correct |
35 ms |
18320 KB |
Output is correct |
14 |
Correct |
34 ms |
18160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
18180 KB |
Output is correct |
2 |
Correct |
35 ms |
18260 KB |
Output is correct |
3 |
Correct |
33 ms |
18204 KB |
Output is correct |
4 |
Correct |
33 ms |
18204 KB |
Output is correct |
5 |
Correct |
33 ms |
18220 KB |
Output is correct |
6 |
Correct |
34 ms |
18240 KB |
Output is correct |
7 |
Correct |
37 ms |
18228 KB |
Output is correct |
8 |
Correct |
37 ms |
18252 KB |
Output is correct |
9 |
Correct |
38 ms |
18252 KB |
Output is correct |
10 |
Correct |
45 ms |
18260 KB |
Output is correct |
11 |
Correct |
34 ms |
18172 KB |
Output is correct |
12 |
Correct |
34 ms |
18228 KB |
Output is correct |
13 |
Correct |
35 ms |
18320 KB |
Output is correct |
14 |
Correct |
34 ms |
18160 KB |
Output is correct |
15 |
Correct |
58 ms |
20568 KB |
Output is correct |
16 |
Correct |
80 ms |
20336 KB |
Output is correct |
17 |
Correct |
58 ms |
20264 KB |
Output is correct |
18 |
Correct |
59 ms |
20636 KB |
Output is correct |
19 |
Correct |
61 ms |
20380 KB |
Output is correct |
20 |
Correct |
59 ms |
20284 KB |
Output is correct |
21 |
Correct |
58 ms |
20392 KB |
Output is correct |
22 |
Correct |
57 ms |
20632 KB |
Output is correct |
23 |
Correct |
54 ms |
20260 KB |
Output is correct |
24 |
Correct |
59 ms |
20340 KB |
Output is correct |
25 |
Correct |
58 ms |
20444 KB |
Output is correct |
26 |
Correct |
67 ms |
20436 KB |
Output is correct |
27 |
Correct |
62 ms |
20392 KB |
Output is correct |
28 |
Correct |
58 ms |
20592 KB |
Output is correct |
29 |
Correct |
58 ms |
20312 KB |
Output is correct |
30 |
Correct |
59 ms |
20360 KB |
Output is correct |
31 |
Correct |
56 ms |
20020 KB |
Output is correct |
32 |
Correct |
58 ms |
20520 KB |
Output is correct |
33 |
Correct |
57 ms |
20204 KB |
Output is correct |
34 |
Correct |
58 ms |
20632 KB |
Output is correct |
35 |
Correct |
57 ms |
20516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
18180 KB |
Output is correct |
2 |
Correct |
35 ms |
18260 KB |
Output is correct |
3 |
Correct |
33 ms |
18204 KB |
Output is correct |
4 |
Correct |
33 ms |
18204 KB |
Output is correct |
5 |
Correct |
33 ms |
18220 KB |
Output is correct |
6 |
Correct |
34 ms |
18240 KB |
Output is correct |
7 |
Correct |
37 ms |
18228 KB |
Output is correct |
8 |
Correct |
37 ms |
18252 KB |
Output is correct |
9 |
Correct |
38 ms |
18252 KB |
Output is correct |
10 |
Correct |
45 ms |
18260 KB |
Output is correct |
11 |
Correct |
34 ms |
18172 KB |
Output is correct |
12 |
Correct |
34 ms |
18228 KB |
Output is correct |
13 |
Correct |
35 ms |
18320 KB |
Output is correct |
14 |
Correct |
34 ms |
18160 KB |
Output is correct |
15 |
Correct |
58 ms |
20568 KB |
Output is correct |
16 |
Correct |
80 ms |
20336 KB |
Output is correct |
17 |
Correct |
58 ms |
20264 KB |
Output is correct |
18 |
Correct |
59 ms |
20636 KB |
Output is correct |
19 |
Correct |
61 ms |
20380 KB |
Output is correct |
20 |
Correct |
59 ms |
20284 KB |
Output is correct |
21 |
Correct |
58 ms |
20392 KB |
Output is correct |
22 |
Correct |
57 ms |
20632 KB |
Output is correct |
23 |
Correct |
54 ms |
20260 KB |
Output is correct |
24 |
Correct |
59 ms |
20340 KB |
Output is correct |
25 |
Correct |
58 ms |
20444 KB |
Output is correct |
26 |
Correct |
67 ms |
20436 KB |
Output is correct |
27 |
Correct |
62 ms |
20392 KB |
Output is correct |
28 |
Correct |
58 ms |
20592 KB |
Output is correct |
29 |
Correct |
58 ms |
20312 KB |
Output is correct |
30 |
Correct |
59 ms |
20360 KB |
Output is correct |
31 |
Correct |
56 ms |
20020 KB |
Output is correct |
32 |
Correct |
58 ms |
20520 KB |
Output is correct |
33 |
Correct |
57 ms |
20204 KB |
Output is correct |
34 |
Correct |
58 ms |
20632 KB |
Output is correct |
35 |
Correct |
57 ms |
20516 KB |
Output is correct |
36 |
Correct |
184 ms |
32104 KB |
Output is correct |
37 |
Correct |
193 ms |
36572 KB |
Output is correct |
38 |
Correct |
195 ms |
36580 KB |
Output is correct |
39 |
Correct |
189 ms |
36708 KB |
Output is correct |
40 |
Correct |
200 ms |
36640 KB |
Output is correct |
41 |
Correct |
180 ms |
36652 KB |
Output is correct |
42 |
Correct |
223 ms |
36632 KB |
Output is correct |
43 |
Correct |
145 ms |
28808 KB |
Output is correct |
44 |
Correct |
161 ms |
33116 KB |
Output is correct |
45 |
Correct |
153 ms |
35084 KB |
Output is correct |
46 |
Correct |
158 ms |
36220 KB |
Output is correct |
47 |
Correct |
155 ms |
36304 KB |
Output is correct |
48 |
Correct |
157 ms |
35132 KB |
Output is correct |
49 |
Correct |
130 ms |
30036 KB |
Output is correct |
50 |
Correct |
168 ms |
35172 KB |
Output is correct |
51 |
Correct |
157 ms |
35256 KB |
Output is correct |
52 |
Correct |
127 ms |
36692 KB |
Output is correct |
53 |
Correct |
129 ms |
36660 KB |
Output is correct |
54 |
Correct |
181 ms |
33864 KB |
Output is correct |
55 |
Correct |
141 ms |
33848 KB |
Output is correct |
56 |
Correct |
121 ms |
37428 KB |
Output is correct |