#include <bits/stdc++.h>
using namespace std;
char change(char c, int count, int k){
if(count % k){
return c;
}
if(c == 'J'){
return 'O';
}
if(c == 'O'){
return 'I';
}
return 'D';
}
int main() {
int n, k, count = 0, ans = 0;
char target = 'J';
string s;
cin >> n >> k >> s;
for(int i = 0; i < n; i++){
if(target == 'D'){
break;
}
if(s[i] != target && count){
ans++;
}
else if(s[i] == target){
count++;
target = change(target, count, k);
}
}
if(target == 'D'){
cout << ans;
}
else{
cout << -1;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |