#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define all(x) x.begin(),x.end();
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,k;
cin>>n>>k;
string str;
cin>>str;
char cur='J';
int cnt=0;
bool tf=false;
int ans=0;
for(int i=0;i<n;i++){
if(str[i]!=cur){
if(tf) ans++;
continue;
}
if(cur=='J' and cnt==0){
tf=true;
}
cnt++;
if(cnt==k){
if(cur=='I'){
cout<<ans;
return 0;
}
else{
if(cur=='J') cur='O';
else cur='I';
}
cnt=0;
}
}
cout<<-1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |