| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1086500 | toast12 | JJOOII 2 (JOI20_ho_t2) | C++14 | 1 ms | 348 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 main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> jpos, opos, ipos;
for (int l = 0; l < n; l++) {
if (s[l] == 'J') jpos.push_back(l);
if (s[l] == 'O') opos.push_back(l);
if (s[l] == 'I') ipos.push_back(l);
}
int ans = INT_MAX;
for (int j = 0; j <= jpos.size()-k; j++) {
int lb = jpos[j+k-1];
auto it = lower_bound(opos.begin(), opos.end(), lb);
if (it == opos.end()) break;
int idx = it-opos.begin();
lb = opos[idx+k-1];
it = lower_bound(ipos.begin(), ipos.end(), lb);
if (it == ipos.end()) break;
idx = it-ipos.begin();
int l = jpos[j], r = ipos[idx+k-1];
ans = min(ans, (r-l+1)-(3*k));
}
if (ans == INT_MAX) ans = -1;
cout << ans << '\n';
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... | ||||
