This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |