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;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,k;
cin>>n>>k;
string s;
cin>>s;
int a=0,b,c,d;
while(s[a]!='J')
{
a++;
if(a==n) return cout<<-1<<endl,0;
}
b=a;
int numj=0;
while(numj<k)
{
if(b==n) return cout<<-1<<endl,0;
if(s[b]=='J') numj++;
b++;
}
c=b;
int numo=0;
while(numo<k)
{
if(c==n) return cout<<-1<<endl,0;
if(s[c]=='O') numo++;
c++;
}
d=c;
int numi=0;
while(numi<k)
{
if(d==n) return cout<<-1<<endl,0;
if(s[d]=='I') numi++;
d++;
}
int kolko=0;
for(int i=a;i<b;i++) if(s[i]!='J') kolko++;
for(int i=b;i<c;i++) if(s[i]!='O') kolko++;
for(int i=c;i<d;i++) if(s[i]!='I') kolko++;
cout<<kolko<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |