이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |