이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MN 200071
using namespace std;
int n, k, F[3][MN];
inline int id (char c) {
return c == 'I' ? 2 : c == 'O';
}
int solve(int p1) {
int len = n - p1 + 1;
int st = p1, dr = n, mij;
for(int cul = 0; cul < 3; ++cul) {
if(F[cul][n] - F[cul][p1-1] < k) return -1;
st = p1, dr = n;
while(st < dr) {
mij = (st + dr) >> 1;
if(F[cul][mij] - F[cul][p1-1] >= k) dr = mij;
else st = mij + 1;
}
p1 = st + 1;
}
return len - (n - p1 + 1) - 3 * k;
}
string S;
int main() {
cin >> n >> k >> S;
for(int i = 1; i <= n; ++i) {
++F[id(S[i-1])][i];
for(int d = 0; d < 3; ++d) F[d][i] += F[d][i-1];
}
int rez = -1, ac = 0;
for(int i = 1; i <= n; ++i) {
ac = solve(i);
if(ac != -1) {
if(rez == -1) rez = ac;
else rez = min(rez, ac);
}
}
cout << rez << "\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... |