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>
#define ll long long
using namespace std;
ll n, k, dem = 0;
map <char, ll> cnt;
char a[5] = {'J', 'O', 'I'};
string s;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k>>s;
ll i = 0, j = 0;
n--;
bool flag = false;
while(i <= n){
if(flag == false){
while(s[i] != 'J' && i <= n){
i++;
}
while(s[n] != 'I' && n > 0){
n--;
}
flag = true;
}
else{
while(cnt[a[j]] < k && i <= n){
if(s[i] == a[j]) cnt[s[i]]++;
else dem++;
i++;
}
j++;
}
// cout<<cnt['J']<<" "<<cnt['O']<<" "<<cnt['I']<<'\n';
}
if(cnt['J'] == cnt['O'] && cnt['O'] == cnt['I'] && cnt['J'] == k) cout<<dem;
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... |