# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227175 | ho94949 | JJOOII 2 (JOI20_ho_t2) | C++17 | 29 ms | 3200 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[202020];
int js[202020], os[202020], is[202020];
int main()
{
scanf("%d%d", &N, &K);
scanf("%s", s+1);
for(int i=1; i<=N; ++i)
{
js[i] = js[i-1], os[i] = os[i-1], is[i] = is[i-1];
if(s[i] == 'J') ++js[i];
if(s[i] == 'O') ++os[i];
if(s[i] == 'I') ++is[i];
}
int ans = -1;
for(int i=0; i<N; ++i)
{
int np = i;
int jp = lower_bound(js+np, js+N+1, js[np]+K) - js;
if(jp == N+1) break;
int op = lower_bound(os+jp, os+N+1, os[jp]+K) - os;
if(op == N+1) break;
int ip = lower_bound(is+op, is+N+1, is[op]+K) - is;
if(ip == N+1) break;
if(ans == -1) ans = ip-np-3*K;
else ans = min(ans, ip-np-3*K);
}
printf("%d\n", ans);
}
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... |