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>
using namespace std;
int n, k;
string s;
int solve() {
int a[n], b[n], c[n];
for (int i = 0; i < n; i++) {
a[i] = b[i] = c[i] = 0;
a[i] += (s[i] == 'J');
b[i] += (s[i] == 'O');
c[i] += (s[i] == 'I');
if (i) {
a[i] += a[i - 1];
b[i] += b[i - 1];
c[i] += c[i - 1];
}
}
int ans = n;
for (int i = 0; i < n; i++) {
int j = lower_bound(a, a + n, k + (i ? a[i - 1] : 0)) - a;
if (j == n) break;
j = lower_bound(b, b + n, k + b[j]) - b;
if (j == n) break;
j = lower_bound(c, c + n, k + c[j]) - c;
if (j == n) break;
ans = min(ans, j - i + 1 - 3 * k);
}
return (ans != n ? ans : -1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k >> s;
cout << solve() << '\n';
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... |