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;
int main() {
int n, k;
string s;
cin >> n >> k >> s;
int pb = -1, pj = 0, po = 0, pi = 0;
int co = 0, cj = 0, ci = 0, rez = -1;
for (;pb < n;pb++) {
if (pb >= 0) {
if (s[pb] == 'J')cj--;
}
for (;pj < n && cj < k;pj++) {
if (s[pj] == 'J')cj++;
if (s[pj] == 'O')co--;
for (;po < n && co < k;po++) {
if (s[po] == 'O')co++;
if (s[po] == 'I')ci--;
for (;pi < n && ci < k;pi++) {
if (s[pi] == 'I')ci++;
}
}
}
if (cj != k || co != k || ci != k)break;
int nrez = pi - pb - 1 - 3 * k;
if (rez == -1)rez = nrez;
rez = min(rez, nrez);
}
cout << rez;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |