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 <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k; cin >> n >> k;
string s; cin >> s;
if(s.find_first_of('J') > s.find_last_of('I')) {
cout << -1;
return 0;
}
s = s.substr(s.find_first_of('J'), s.find_last_of('I') - s.find_first_of('J') + 1);
n = s.size();
ll mn = 1e10;
for(int i = 0; i < n; i++) {
char c = s[i];
if(c != 'J') continue;
ll ileo = 0, ilej = 1, ilei = 0, usu = 0;
for(int j = i+1; j < n; j++) {
char z = s[j];
if(z == 'O') {
if(ileo < k) {
ilei = 0;
ileo++;
} else {
usu++;
}
}
if(z == 'J') {
if(ilej < k) {
ileo = 0;
ilei = 0;
ilej++;
} else {
usu++;
}
}
if(z == 'I') {
if(ilei + 1 >= k && ilej >= k && ileo >= k) {
ilei++;
break;
} else {
ilei++;
}
}
}
if(ilei >= k && ileo >= k && ilej >= k) {
mn = min(usu, mn);
}
}
cout << (mn <= 2e8 ? mn : -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... |