이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |