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;
for(int i=0;i<n;i++){
if(s[i]=='J'){
cev=0;
stop=false;
int say=0,tut=0;
for(int j=i;j<n;j++){
if(say==0 && s[j]=='J'){
tut++;
}
else if(say==1 && s[j]=='O'){
tut++;
}
else if(say==2 && s[j]=='I'){
tut++;
}
else cev++;
if(tut==k){
say=1;
}
else if(tut==2*k){
say=2;
stop=true;
break;
}
}
//cout<<cev<<endl;
}
if(stop)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... |