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>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, k, res = n; string s; cin >> n >> k >> s;
for (int l = 0, j = 0, o = 0, i = 0, cj = 0, co = 0, ci = 0; l < n; ++l) {
while (j < n && cj < k) {
if (s[j] == 'J') ++cj;
if (s[j] == 'O') --co;
++j;
}
while (o < n && co < k) {
if (s[o] == 'O') ++co;
if (s[o] == 'I') --ci;
++o;
}
while (i < n && ci < k) if (s[i++] == 'I') ++ci;
if (ci != k) break;
res = min(res, i - l - 3 * k);
if (s[l] == 'J') --cj;
}
cout << (res < n ? res : -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... |