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