結果

問題 No.1077 Noelちゃんと星々4
ユーザー しのしの
提出日時 2020-05-05 21:41:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 524 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 198,972 KB
実行使用メモリ 42,908 KB
最終ジャッジ日時 2023-09-09 11:50:56
合計ジャッジ時間 3,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
42,716 KB
testcase_01 AC 15 ms
42,712 KB
testcase_02 AC 27 ms
42,800 KB
testcase_03 AC 30 ms
42,860 KB
testcase_04 AC 20 ms
42,860 KB
testcase_05 AC 19 ms
42,800 KB
testcase_06 AC 21 ms
42,868 KB
testcase_07 AC 22 ms
42,712 KB
testcase_08 AC 20 ms
42,828 KB
testcase_09 AC 20 ms
42,832 KB
testcase_10 AC 30 ms
42,796 KB
testcase_11 AC 26 ms
42,904 KB
testcase_12 AC 23 ms
42,796 KB
testcase_13 AC 18 ms
42,796 KB
testcase_14 AC 30 ms
42,716 KB
testcase_15 AC 23 ms
42,792 KB
testcase_16 AC 20 ms
42,792 KB
testcase_17 AC 24 ms
42,792 KB
testcase_18 AC 30 ms
42,908 KB
testcase_19 AC 18 ms
42,808 KB
testcase_20 AC 15 ms
42,860 KB
testcase_21 AC 32 ms
42,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int INF = 1000000007;
const int MaxN = 1005;
const int MaxY = 10005;

int dp[MaxN][MaxY];
int y[MaxY];
int n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", y+i);
  fill(dp[0], dp[MaxN], INF);
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < MaxY-1; j++) dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
    for (int j = 0; j < MaxY; j++) dp[i+1][j] = dp[i][j] + abs(j-y[i]);
  }
  printf("%d\n", *min_element(dp[n], dp[n+1]));
}
0