# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
273017 | ChrisT | JJOOII 2 (JOI20_ho_t2) | C++17 | 31 ms | 2048 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;
char s[200'005];
int main() {
int n,k;
scanf ("%d %d",&n,&k);
scanf ("%s",s+1);
vector<int> js,os,is;
for (int i = 1; i <= n; i++) {
if (s[i] == 'J') js.push_back(i);
else if (s[i] == 'O') os.push_back(i);
else is.push_back(i);
}
int ret = 1e9;
for (int i = 1; i <= n; i++) {
int needJ = lower_bound(js.begin(),js.end(),i) - js.begin();
needJ += k-1;
if (needJ < (int)js.size()) {
int pos = js[needJ];
int needO = lower_bound(os.begin(),os.end(),pos) - os.begin();
needO += k-1;
if (needO < (int)os.size()) {
pos = os[needO];
int needI = lower_bound(is.begin(),is.end(),pos) - is.begin();
needI += k-1;
if (needI < (int)is.size()) {
pos = is[needI];
ret = min(ret,n - (i-1) - (n-pos) - k*3);
}
}
}
}
printf ("%d\n",ret<1e9?ret:-1);
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... |