이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5 + 5;
int sj[nmax],so[nmax],si[nmax];
int main () {
int n,k; cin >> n >> k;
string t; cin >> t;
t = "X" + t;
for(int i=1; i<=n; i++) {
sj[i] = sj[i-1] + (t[i]=='J');
so[i] = so[i-1] + (t[i]=='O');
si[i] = si[i-1] + (t[i]=='I');
}
int j = 0;
int o = 0;
int i = 0;
int mn = 1e9;
for(int l=0; l<n; l++) {
while(j<=n and sj[j]-sj[l]<k) j++;
while(o<=n and so[o]-so[j]<k) o++;
while(i<=n and si[i]-si[o]<k) i++;
if(j<=n and o<=n and i<=n and i-l<mn)
mn = i - l;
}
mn = mn - 3*k;
if(mn>n) mn = -1;
cout << mn;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |