This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |