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 <stdio.h>
#include <string.h>
#define N 200000
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
char *joi = "JOI";
int main() {
static char cc[N + 1];
static int qu[N], jj[N + 1], jj_[N + 1];
int n, cnt, k, i, h, ans;
scanf("%d%d%s", &n, &k, cc);
for (i = 0; i <= n; i++)
jj[i] = i;
for (h = 2; h >= 0; h--) {
cnt = 0;
jj_[n] = -1;
for (i = n - 1; i >= 0; i--) {
if (cc[i] == joi[h])
qu[cnt++] = i;
jj_[i] = cnt >= k ? jj[qu[cnt - k] + 1] : -1;
}
memcpy(jj, jj_, (n + 1) * sizeof *jj_);
}
ans = INF;
for (i = 0; i < n; i++)
if (jj[i] != -1)
ans = min(ans, jj[i] - i - k * 3);
if (ans == INF)
ans = -1;
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
ho_t2.c: In function 'main':
ho_t2.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d%d%s", &n, &k, cc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |