Submission #944536

#TimeUsernameProblemLanguageResultExecution timeMemory
944536rainboy막대기 (KOI13_game)C11
100 / 100
59 ms4584 KiB
#include <stdio.h> #define N 100000 int abs_(int a) { return a > 0 ? a : -a; } long long max(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], ww[N]; int compare_x(int i, int j) { return xx[i] - xx[j]; } int compare_y(int i, int j) { return yy[i] - yy[j]; } int compare_xy(int i, int j) { return xx[i] != xx[j] ? xx[i] - xx[j] : yy[i] - yy[j]; } int (*compare)(int, int); 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 = compare(ii[j], 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; } } int main() { static int ii[N]; static long long dpx[N], dpy[N]; int n, l, h, i, x, y; long long zx, zy, ans; scanf("%d%d", &n, &l); for (i = 0; i < n; i++) { scanf("%d%d", &xx[i], &yy[i]); ww[i] = abs_(xx[i] - yy[i]) + l; } for (i = 0; i < n; i++) ii[i] = i; compare = compare_x, sort(ii, 0, n); for (i = 0, x = 0; i < n; i++) xx[ii[i]] = i + 1 == n || xx[ii[i + 1]] != xx[ii[i]] ? x++ : x; compare = compare_y, sort(ii, 0, n); for (i = 0, y = 0; i < n; i++) yy[ii[i]] = i + 1 == n || yy[ii[i + 1]] != yy[ii[i]] ? y++ : y; compare = compare_xy, sort(ii, 0, n); ans = 0; for (h = 0; h < n; h++) { i = ii[h], x = xx[i], y = yy[i]; zx = dpx[x] + ww[i], zy = dpy[y] + ww[i]; ans = max(ans, max(zx, zy)); dpy[y] = max(dpy[y], zx); dpx[x] = max(dpx[x], zy); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

game.c: In function 'main':
game.c:50:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d", &n, &l);
      |  ^~~~~~~~~~~~~~~~~~~~~
game.c:52:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |   scanf("%d%d", &xx[i], &yy[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...
#Verdict Execution timeMemoryGrader output
Fetching results...