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;
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |