Submission #944564

#TimeUsernameProblemLanguageResultExecution timeMemory
944564rainboy수족관 3 (KOI13_aqua3)C11
100 / 100
67 ms12888 KiB
#include <stdio.h> #include <string.h> #define N 150000 int min(int a, int b) { return a < b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } long long aa[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) if (aa[ii[j]] == aa[i_]) j++; else if (aa[ii[j]] < aa[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 main() { static int xx[N + 1], yy[N], ll[N], rr[N], pp[N], qu[N], dd[N], ii[N], jj[N]; int n, k, cnt, h, i, i_, j, p; long long area; scanf("%d%*d%*d", &n), n = n / 2 - 1; xx[0] = 0; for (i = 0; i < n; i++) scanf("%*d%*d%d%d", &xx[i + 1], &yy[i]); scanf("%*d%*d"); cnt = 0; for (i = 0; i < n; i++) { while (cnt && yy[qu[cnt - 1]] > yy[i]) cnt--; ll[i] = cnt == 0 ? -1 : qu[cnt - 1]; qu[cnt++] = i; } cnt = 0; for (i = n - 1; i >= 0; i--) { while (cnt && yy[qu[cnt - 1]] >= yy[i]) cnt--; rr[i] = cnt == 0 ? n : qu[cnt - 1]; qu[cnt++] = i; } for (i = 0; i < n; i++) { pp[i] = rr[i] == n || ll[i] != -1 && yy[ll[i]] > yy[rr[i]] ? ll[i] : rr[i]; if (pp[i] != -1) dd[pp[i]]++; } memset(jj, -1, n * sizeof *jj); cnt = 0; for (i = 0; i < n; i++) { i_ = i; while (dd[i_] == 0) { p = pp[i_], j = jj[i_]; aa[i_] = (j == -1 ? 0 : aa[j]) + (long long) (xx[rr[i_]] - xx[ll[i_] + 1]) * (yy[i_] - (p == -1 ? 0 : yy[p])); dd[i_] = -1; if (p == -1) break; dd[p]--; if (jj[p] == -1) jj[p] = i_; else if (aa[jj[p]] < aa[i_]) { if (jj[p] != -1) ii[cnt++] = jj[p]; jj[p] = i_; } else ii[cnt++] = i_; i_ = p; } } for (i = 0; i < n; i++) if (pp[i] == -1) { ii[cnt++] = i; break; } sort(ii, 0, cnt); scanf("%d", &k), k = min(k, cnt); area = 0; for (h = cnt - k; h < cnt; h++) area += aa[ii[h]]; printf("%lld\n", area); return 0; }

Compilation message (stderr)

aqua3.c: In function 'main':
aqua3.c:60:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   60 |   pp[i] = rr[i] == n || ll[i] != -1 && yy[ll[i]] > yy[rr[i]] ? ll[i] : rr[i];
      |                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
aqua3.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%*d%*d", &n), n = n / 2 - 1;
      |  ^~~~~~~~~~~~~~~~~~~~~
aqua3.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%*d%*d%d%d", &xx[i + 1], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aqua3.c:44:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%*d%*d");
      |  ^~~~~~~~~~~~~~~
aqua3.c:92:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |  scanf("%d", &k), k = min(k, cnt);
      |  ^~~~~~~~~~~~~~~
#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...