제출 #501321

#제출 시각아이디문제언어결과실행 시간메모리
501321rainboyTortoise (CEOI21_tortoise)C11
8 / 100
1 ms332 KiB
#include <assert.h> #include <stdio.h> #include <stdlib.h> #define N 5000 #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } int dp[N * 2 + 1], n, offset; void op2(int a, int b) { int k; for (k = n * 2; k >= 0; k--) if (dp[k] != -INF && dp[k] >= b - offset) dp[k + 1] = max(dp[k + 1], dp[k] - a * 2); else assert(k + 2 > n * 2 || dp[k + 2] == -INF); } int main() { static int aa[N]; int h, i, j, k, r, ans; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (k = 0; k <= n * 2; k++) dp[k] = -INF; dp[0] = 0; for (i = -1, j = 0; j <= n; j++) if (j == n || aa[j] == -1) { int d_, h_, i_, j_; d_ = -1, h_ = -1; for (h = i + 1; h <= j; h++) if (aa[h] > 0) { int d = INF; if (i != -1) d = min(d, h - i); if (j != n) d = min(d, j - h); if (d_ < d) d_ = d, h_ = h; } i_ = max(i, 0), j_ = min(j, n - 1); if (d_ == -1) offset += j_ - i_; else { for (h = i + 1; h < h_; h++) for (r = 0; r < aa[h]; r++) op2(h - i, i - h); if (j == n || i >= 0 && h_ - i <= j - h_) { for (r = 0; r < aa[h_] - 1; r++) op2(h_ - i, i - h_); offset += j_ - i_, op2(0, j_ - h_); } else { offset += j_ - i_, op2(0, j_ - h_); for (r = 0; r < aa[h_] - 1; r++) op2(j - h_, (j - h_) * 3); } for (h = h_ + 1; h < j; h++) for (r = 0; r < aa[h]; r++) op2(j - h, (j - h) * 3); } i = j; } ans = 0; for (i = 0; i < n; i++) if (aa[i] > 0) ans += aa[i]; k = 0; while (k < n * 2 && dp[k + 1] != -INF) k++; ans -= k; printf("%d\n", ans); return 0; }

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

tortoise.c: In function 'main':
tortoise.c:56:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   56 |     if (j == n || i >= 0 && h_ - i <= j - h_) {
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~~
tortoise.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
tortoise.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d", &aa[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...