n,k = map(int, input().split())
s = input()
def test1(a):
J=0;O=0;I=0
for p in range(a,n):
i = s[p]
if J==k and O==k and i=="I":
I+=1
elif J==k and i=="O":
O+=1
elif i=="J":
J+=1
return I>=k,I
lo=-1;hi=n
while lo<hi:
mid = (lo+hi+1)//2
if test1(mid)[0]:
lo = mid
else:
hi = mid-1
if lo==-1:
print(-1)
else:
p = "".join(reversed(list(s)))
cnt = 0
ans = 0
for i in p:
if i=="I":
cnt += 1
if cnt > test1(lo)[1]-k:
break
ans += 1
print(n-ans-lo-k*3)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
18220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
18220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
18220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |