이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |