이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;
int pref[4][200001], ptr[4];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
string s;
cin >> n >> k >> s;
FOR(i, 0, n) {
FOR(j, 1, 4) pref[j][i + 1] = pref[j][i];
if (s[i] == 'J') pref[1][i + 1]++;
if (s[i] == 'O') pref[2][i + 1]++;
if (s[i] == 'I') pref[3][i + 1]++;
}
int ans = INT_MAX;
for (ptr[0] = 0; ptr[0] <= n; ptr[0]++) {
FOR(i, 1, 4) while (ptr[i] < ptr[i - 1] || (ptr[i] <= n && pref[i][ptr[i]] - pref[i][ptr[i - 1]] < k)) ptr[i]++;
bool possible = true;
FOR(i, 1, 4) if (ptr[i] > n || pref[i][ptr[i]] - pref[i][ptr[i - 1]] < k) possible = false;
if (possible) ans = min(ans, ptr[3] - ptr[0] - 3 * k);
}
if (ans == INT_MAX) cout << -1;
else 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... |