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;
#define endl '\n'
typedef long long ll;
int cnt[3];
int ans;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N,K; cin >> N >> K;
int first = 0; int last = N - 1;
string s; cin >> s;
for(int i = 0; i < N; i++) {
if(cnt[0] != K) {
if(s[i] == 'J') cnt[0]++;
else{
if(i == first) first++;
else if(i == last) last--;
else ans++;
}
}
else if(cnt[1] != K) {
if(s[i] == 'O') cnt[1]++;
else{
if(i == first) first++;
else if(i == last) last--;
else ans++;
}
}
else if(cnt[2] != K) {
if(s[i] == 'I') cnt[2]++;
else{
if(i == first) first++;
else if(i == last) last--;
else ans++;
}
}
}
for(int i = 0; i < 3; i++) {
if(cnt[i] != K) {
cout << -1;
return 0;
}
}
cout << ans;
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... |