이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int positions[n][3];
string opt = "JOI";
for (int i = 0; i < 3; i++) {
int leftPointer = 0, rightPointer = 0, count = 0;
if (s[0] == opt[i]){
count++;
}
while (leftPointer < n) {
while (count < k && rightPointer < n) {
rightPointer++;
if (rightPointer == n){
break;;
}
if (s[rightPointer] == opt[i]){
count++;
}
}
if (count < k) {
positions[leftPointer][i] = INT_MAX;
leftPointer++;
continue;
}
positions[leftPointer][i] = rightPointer;
if (s[leftPointer] == opt[i]){
count--;
}
leftPointer++;
}
}
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
int leftPointer = i, rightPointer = positions[i][0];
for (int j = 1; j < 3; j++) {
if (rightPointer == INT_MAX){
continue;
}
rightPointer = positions[rightPointer][j];
}
ans = min(ans, rightPointer - leftPointer + 1 - 3 * k);
}
if (ans > n)
cout << -1;
else
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |