#include<bits/stdc++.h>
using namespace std;
char s[]={'J','O','I','Z'};
char *c = s;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;int p = 0;int chk = 0;
string a;cin>>a;int cnt = 0;int ch=0;
for(int i=0;i<=n;i++){
//cout<<"O";
if(a[i]==*c&&chk==0){
cnt++;chk=1;
if(cnt%m==0){
c++;
}
//cout<<"1";
}
else if(*c=='Z'){
ch = 1;
//cout<<"final";
break;
}
else if(a[i]==*c){
cnt++;
if(cnt%m==0){
c++;
}
//cout<<c;
}
else if(chk){
p++;
//cout<<"3";
}
}
if(ch){
cout<<p;
}
else{
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 |
- |