# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
212523 | DystoriaX | JJOOII 2 (JOI20_ho_t2) | C++14 | 18 ms | 2676 KiB |
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 n, k;
char s[200010];
vector<int> J, O, I;
int lf[200010];
int ans = 1e9;
int main(){
scanf("%d%d", &n, &k);
scanf(" %s", s + 1);
for(int i = 1; i <= n; i++){
if(s[i] == 'J') J.emplace_back(i);
if(s[i] == 'O') O.emplace_back(i);
if(s[i] == 'I') I.emplace_back(i);
}
for(int i = k - 1; i < (int) J.size(); i++){
lf[J[i]] = J[i - k + 1];
}
for(int i = k - 1; i < (int) O.size(); i++){
auto it = upper_bound(J.begin(), J.end(), O[i - k + 1]);
if(it == J.begin()) continue;
--it;
if(lf[*it] == 0) continue;
lf[O[i]] = lf[*it];
}
for(int i = k - 1; i < (int) I.size(); i++){
auto it = upper_bound(O.begin(), O.end(), I[i - k + 1]);
if(it == O.begin()) continue;
--it;
if(lf[*it] == 0) continue;
ans = min(ans, I[i] - lf[*it] + 1 - 3 * k);
}
if(ans == 1e9) ans = -1;
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |