#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |