Submission #550658

#TimeUsernameProblemLanguageResultExecution timeMemory
550658rainboy여별 열쇠 (JOI15_keys)C11
100 / 100
1 ms340 KiB
#include <stdio.h> #define N 2000 #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int xx[N * 2], xx_[N * 2], yy[N * 2]; 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 main() { static int ii[N * 2], dp[N + 1][2]; int n, m, k, i, i_, j, c; scanf("%d%d%d", &n, &m, &k), k = n - k; for (i = 0; i < n * 2; i++) { scanf("%d", &xx[i]); ii[i] = i; } sort(ii, 0, n * 2); for (i = 0; i < n * 2; i++) xx_[ii[i]] = i; for (i = 0; i + 1 < n * 2; i++) yy[i] = xx[ii[i + 1]] - xx[ii[i]]; for (c = 0; c <= k; c++) dp[c][0] = dp[c][1] = INF; dp[0][0] = 0; for (i = 0; i + 1 < n * 2; i++) if ((ii[i] & 1) == 0) { if ((ii[i] ^ ii[i + 1]) == 1) for (c = k; c >= 0; c--) dp[c][0] = min(dp[c][0], c == 0 ? INF : dp[c - 1][0] + yy[i]); else if ((ii[i + 1] & 1) == 0) { for (i_ = i; (ii[i_] & 1) == 0; i_ = j) { j = xx_[ii[i_] ^ 1] - 1; for (c = k; c >= 0; c--) { dp[c][0] = min(dp[c][0], dp[c][1]); dp[c][1] = c == 0 ? INF : min(min(dp[c - 1][0] + yy[i_], dp[c - 1][1]) + yy[j], INF); } } for (c = k; c >= 0; c--) dp[c][0] = min(dp[c][0], dp[c][1]), dp[c][1] = INF; } } printf("%d\n", m - dp[k][0]); return 0; }

Compilation message (stderr)

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