結果

問題 No.1077 Noelちゃんと星々4
ユーザー SSRSSSRS
提出日時 2020-06-12 21:32:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 169,744 KB
実行使用メモリ 42,108 KB
最終ジャッジ日時 2023-09-06 09:53:03
合計ジャッジ時間 3,017 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 36 ms
30,060 KB
testcase_03 AC 47 ms
38,032 KB
testcase_04 AC 15 ms
13,704 KB
testcase_05 AC 12 ms
11,092 KB
testcase_06 AC 19 ms
16,456 KB
testcase_07 AC 22 ms
18,572 KB
testcase_08 AC 16 ms
14,336 KB
testcase_09 AC 14 ms
12,824 KB
testcase_10 AC 46 ms
37,960 KB
testcase_11 AC 31 ms
25,744 KB
testcase_12 AC 25 ms
21,656 KB
testcase_13 AC 11 ms
10,436 KB
testcase_14 AC 46 ms
37,096 KB
testcase_15 AC 24 ms
20,996 KB
testcase_16 AC 17 ms
14,660 KB
testcase_17 AC 28 ms
23,316 KB
testcase_18 AC 47 ms
38,552 KB
testcase_19 AC 11 ms
10,124 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 52 ms
42,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int INF = 100000000;
int main(){
  int N;
  cin >> N;
  vector<int> Y(N);
  for (int i = 0; i < N; i++){
    cin >> Y[i];
  }
  vector<vector<int>> dp(N + 1, vector<int>(10001, INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; i++){
    for (int j = 1; j <= 10000; j++){
      dp[i][j] = min(dp[i][j], dp[i][j - 1]);
    }
    for (int j = 0; j <= 10000; j++){
      dp[i + 1][j] = dp[i][j] + abs(j - Y[i]);
    }
  }
  int ans = INF;
  for (int i = 0; i <= 10000; i++){
    ans = min(ans, dp[N][i]);
  }
  cout << ans << endl;
}
0