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 <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> J, O, I;
for(int i = 0; i < n; i ++) {
if(s[i] == 'J') {
J.push_back(i);
}
if(s[i] == 'O') {
O.push_back(i);
}
if(s[i] == 'I') {
I.push_back(i);
}
}
int ans = 1e9;
for(int i = 0; i < (int) J.size() - k + 1; i ++) {
int pos_o = lower_bound(O.begin(), O.end(), J[i + k - 1]) - O.begin();
if(pos_o < (int) O.size() - k + 1) {
int pos_i = lower_bound(I.begin(), I.end(), O[pos_o + k - 1]) - I.begin();
if(pos_i < (int) I.size() - k + 1) {
int term = I[pos_i + k - 1];
ans = min(ans, term - J[i] + 1 - 3 * k);
}
}
}
if(ans == 1e9) {
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... |