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 N=2e5+5;
int n,k,ans,d,x,y; string s;
vector <int> j,o,_i;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k>>s;
for (int i=0; i<n; i++){
if (s[i]=='J'){
j.push_back(i+1);
}
if (s[i]=='O'){
o.push_back(i+1);
}
if (s[i]=='I'){
_i.push_back(i+1);
}
} ans=1e9;
for (int i=0; i<(int)o.size()-k+1; i++){
x=lower_bound(j.begin(),j.end(),o[i])-1-j.begin();
y=lower_bound(_i.begin(),_i.end(),o[i+k-1])-_i.begin();
if (x<k-1) continue;
if (y>(int)_i.size()-k) continue;
ans=min(ans,_i[y+k-1]-j[x-k+1]+1-3*k);
}
cout<<(ans<1e9?ans:-1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |