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;
#define int long long
#define OYY 1000000000005
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mid (start+end)/2
#define mod 1000000007
int32_t main(){
faster
int n,k;cin>>n>>k;
string s;cin>>s;
int ger=OYY,cev=OYY;
bool stop=false,pl=false,th=false;
for(int i=0;i<n;i++){
if(s[i]=='J'){
cev=0;
stop=false;
pl=false;
th=false;
int j,tut=0;
for(j=i;j<n;j++){
if(s[j]=='J')tut++;
else cev++;
if(tut==k){
stop=true;
break;
}
}
tut=0;
j++;
// cout<<j<<endl;
for(;j<n && stop;j++){
//cout<<s[j]<<" "<<tut<<endl;
if(s[j]=='O')tut++;
else cev++;
if(tut==k){
pl=true;
break;
}
}
tut=0;
j++;
// cout<<j<<endl;
for(;j<n && pl;j++){
if(s[j]=='I')tut++;
else cev++;
if(tut==k){
th=true;
break;
}
}
//cout<<stop<<" "<<pl<<" "<<th<<endl;
}
if(th)ger=min(ger,cev);
}
if(ger==OYY)ger=-1;
cout<<ger<<'\n';
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... |