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