이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
string S;
cin >> S;
vector<int> J(N, N + 1), O(N, N + 1), I(N, N + 1);
for (int l = 0, r = 0, c = 0; l < N; l++) {
while (r < N && c < K) {
c += S[r] == 'J';
r++;
}
J[l] = (c == K ? r : N + 1);
c -= S[l] == 'J';
}
for (int l = 0, r = 0, c = 0; l < N; l++) {
while (r < N && c < K) {
c += S[r] == 'O';
r++;
}
O[l] = (c == K ? r : N + 1);
c -= S[l] == 'O';
}
for (int l = 0, r = 0, c = 0; l < N; l++) {
while (r < N && c < K) {
c += S[r] == 'I';
r++;
}
I[l] = (c == K ? r : N + 1);
c -= S[l] == 'I';
}
int ans = N + 1;
for (int i = 0; i < N; i++) {
if (J[i] >= N || O[J[i]] >= N || I[O[J[i]]] > N) {
continue;
}
ans = min(ans, I[O[J[i]]] - i - 3 * K);
}
cout << (ans == N + 1 ? -1 : ans) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |