제출 #548887

#제출 시각아이디문제언어결과실행 시간메모리
548887rainboyPinball (JOI14_pinball)C11
100 / 100
136 ms23372 KiB
#include <stdio.h> #include <string.h> #define N 100000 #define N3 (N * 3 + 2) #define N_ (1 << 19) /* N_ = pow2(ceil(log2(N3))) */ #define INF 0x3f3f3f3f3f3f3f3fLL long long min(long long a, long long b) { return a < b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int xx[N3]; void sort(int *ii, int l, int r) { while (l < r) { int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; while (j < k) if (xx[ii[j]] == xx[i_]) j++; else if (xx[ii[j]] < xx[i_]) { tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; i++, j++; } else { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } sort(ii, l, i); l = k; } } int n_; void update(long long *st, int i, long long x) { for (i += n_; i > 0; i >>= 1) st[i] = min(st[i], x); } long long query(long long *st, int l, int r) { long long x = INF; for (l += n_, r += n_; l <= r; l >>= 1, r >>= 1) { if ((l & 1) == 1) x = min(x, st[l++]); if ((r & 1) == 0) x = min(x, st[r--]); } return x; } int main() { static int cc[N], ii[N3]; static long long st1[N_ * 2], st2[N_ * 2]; int n, n3, m, i, x; long long ans; scanf("%d%d", &n, &m), n3 = n * 3 + 2; for (i = 0; i < n; i++) scanf("%d%d%d%d", &xx[i * 3 + 0], &xx[i * 3 + 1], &xx[i * 3 + 2], &cc[i]); xx[n * 3] = 1, xx[n * 3 + 1] = m; for (i = 0; i < n3; i++) ii[i] = i; sort(ii, 0, n3); for (i = 0, x = 0; i < n3; i++) xx[ii[i]] = i + 1 == n3 || xx[ii[i + 1]] != xx[ii[i]] ? x++ : x; n_ = 1; while (n_ < n3) n_ <<= 1; memset(st1, 0x3f, n_ * 2 * sizeof *st1), memset(st2, 0x3f, n_ * 2 * sizeof *st2); update(st1, xx[n * 3], 0), update(st2, xx[n * 3 + 1], 0); ans = INF; for (i = 0; i < n; i++) { long long x1 = query(st1, xx[i * 3 + 0], xx[i * 3 + 1]); long long x2 = query(st2, xx[i * 3 + 0], xx[i * 3 + 1]); if (x1 != INF && x2 != INF) ans = min(ans, x1 + x2 + cc[i]); if (x1 != INF) update(st1, xx[i * 3 + 2], x1 + cc[i]); if (x2 != INF) update(st2, xx[i * 3 + 2], x2 + cc[i]); } if (ans == INF) ans = -1; printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

pinball.c: In function 'main':
pinball.c:63:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |  scanf("%d%d", &n, &m), n3 = n * 3 + 2;
      |  ^~~~~~~~~~~~~~~~~~~~~
pinball.c:65:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%d%d%d%d", &xx[i * 3 + 0], &xx[i * 3 + 1], &xx[i * 3 + 2], &cc[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...