| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 831920 | rainboy | Solar Storm (NOI20_solarstorm) | C11 | 263 ms | 127268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
int max(int a, int b) { return a > b ? a : b; }
int n, k;
long long xx[N], ss[N + 1]; int ll[N], rr[N];
int *ej[N], eo[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int qu[N], cnt; long long s_; int i_;
void dfs(int i) {
int o;
long long s;
qu[cnt++] = i;
s = ss[rr[i]] - ss[ll[qu[max(cnt - k, 0)]]];
if (s_ < s)
s_ = s, i_ = i;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
dfs(j);
}
cnt--;
}
int main() {
static int pp[N];
int i, j, l, r;
long long d;
scanf("%d%d%lld", &n, &k, &d);
for (i = 1; i < n; i++)
scanf("%lld", &xx[i]), xx[i] += xx[i - 1];
for (i = 1; i <= n; i++)
scanf("%lld", &ss[i]), ss[i] += ss[i - 1];
for (i = 0, l = 0, r = 0; i < n; i++) {
while (l < i && xx[i] - xx[l] > d)
l++;
while (r < n && xx[r] - xx[i] <= d)
r++;
ll[i] = l, rr[i] = r;
}
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
pp[0] = -1;
for (i = 0, j = 1; j < n; j++) {
while (rr[i] < ll[j])
i++;
pp[j] = i, append(i, j);
}
s_ = 0, i_ = -1, dfs(0);
cnt = 0;
while (cnt < k && i_ != -1)
qu[cnt++] = i_, i_ = pp[i_];
printf("%d\n", cnt);
while (cnt--)
printf("%d ", qu[cnt] + 1);
printf("\n");
return 0;
}컴파일 시 표준 에러 (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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
