Submission #684849

#TimeUsernameProblemLanguageResultExecution timeMemory
684849rainboyLong Distance Coach (JOI17_coach)C11
71 / 100
2024 ms10048 KiB
#include <stdio.h> #define N 200002 #define M 200001 #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; } long long yy[N]; int cc[N], n; long long qq[M], rr[M]; int m; long long l, t; long long *vv; 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 (vv[ii[j]] == vv[i_]) j++; else if (vv[ii[j]] < vv[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 hh[M], ii[N]; static long long aa[N], dp[N], dq[N]; int w, h, i, j; long long x, a, ans; scanf("%lld%d%d%d%lld", &l, &m, &n, &w, &t), m++, n += 2; for (h = 0; h + 1 < m; h++) { scanf("%lld", &x); qq[h] = x / t, rr[h] = x % t; } qq[m - 1] = l / t, rr[h] = l % t; for (h = 0; h < m; h++) hh[h] = h; vv = rr, sort(hh, 0, m); yy[0] = 0, cc[0] = 0; for (i = 1; i < n; i++) scanf("%lld%d", &yy[i], &cc[i]); yy[n - 1] = t, cc[n - 1] = 0; for (i = 0; i < n; i++) ii[i] = i; vv = yy, sort(ii, 0, n); for (i = 0; i + 1 < n; i++) aa[i] = qq[m - 1] + (rr[m - 1] >= yy[ii[i]] ? 1 : 0); dp[0] = aa[0] * w - cc[0], dq[0] = INF; for (j = 1, h = 0; j < n; j++) { a = INF; while (h < m && rr[hh[h]] < yy[ii[j]]) a = min(a, qq[hh[h++]]); if (a == INF) dq[j] = min(dq[j - 1] + aa[j - 1] * w, dp[j - 1]); else { dq[j] = INF; for (i = j - 1; i >= 0; i--) { dq[j] = min(dq[j], dp[i] + a * w * (j - i - 1)); dq[j] = min(dq[j], dq[i] + a * w * (j - i)); } } dp[j] = dq[j] + aa[j] * w - cc[ii[j]]; } ans = dp[n - 1] - aa[n - 1] * w; for (i = 0; i < n; i++) ans += cc[i]; printf("%lld\n", ans); return 0; }

Compilation message (stderr)

coach.c: In function 'main':
coach.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%lld%d%d%d%lld", &l, &m, &n, &w, &t), m++, n += 2;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%lld", &x);
      |   ^~~~~~~~~~~~~~~~~
coach.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%lld%d", &yy[i], &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...