제출 #473622

#제출 시각아이디문제언어결과실행 시간메모리
473622rainboyCover (COCI18_cover)C11
120 / 120
3 ms332 KiB
#include <stdio.h> #define N 5000 #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[N], yy[N]; 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) { int c = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : yy[ii[j]] - yy[i_]; if (c == 0) j++; else if (c < 0) { 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; } } long long xx_[N], yy_[N]; double cross(int i, int j, int k) { return (double) (xx_[j] - xx_[i]) * (yy_[k] - yy_[i]) - (double) (xx_[k] - xx_[i]) * (yy_[j] - yy_[i]); } long long eval(int i, int x) { return xx_[i] * x + yy_[i]; } int main() { static int ii[N], qu[N]; static long long dp[N + 1]; int n, n_, i, j, head, cnt; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &xx[i], &yy[i]); if (xx[i] < 0) xx[i] = -xx[i]; if (yy[i] < 0) yy[i] = -yy[i]; ii[i] = i; } sort(ii, 0, n); n_ = 0; for (i = 0; i < n; i++) { while (n_ > 0 && yy[ii[n_ - 1]] <= yy[ii[i]]) n_--; ii[n_++] = ii[i]; } n = n_; dp[0] = 0; head = cnt = 0; for (j = 1; j <= n; j++) { int x; xx_[j - 1] = yy[ii[j - 1]], yy_[j - 1] = dp[j - 1]; while (cnt >= 2 && cross(qu[head + cnt - 2], qu[head + cnt - 1], j - 1) >= 0) cnt--; qu[head + cnt++] = j - 1; x = xx[ii[j - 1]]; while (cnt >= 2 && eval(qu[head], x) >= eval(qu[head + 1], x)) head++, cnt--; dp[j] = eval(qu[head], x); } printf("%lld\n", dp[n] * 4); return 0; }

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

cover.c: In function 'main':
cover.c:53:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
cover.c:55:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...