結果

問題 No.1077 Noelちゃんと星々4
ユーザー m-44m-44
提出日時 2020-06-12 21:38:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 754 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 165,520 KB
実行使用メモリ 42,416 KB
最終ジャッジ日時 2023-09-06 09:57:58
合計ジャッジ時間 2,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 18 ms
32,064 KB
testcase_03 AC 22 ms
38,140 KB
testcase_04 AC 9 ms
15,700 KB
testcase_05 AC 7 ms
11,532 KB
testcase_06 AC 10 ms
17,660 KB
testcase_07 AC 11 ms
19,724 KB
testcase_08 AC 9 ms
15,684 KB
testcase_09 AC 8 ms
13,584 KB
testcase_10 AC 22 ms
38,128 KB
testcase_11 AC 15 ms
25,888 KB
testcase_12 AC 13 ms
23,804 KB
testcase_13 AC 7 ms
11,580 KB
testcase_14 AC 22 ms
38,164 KB
testcase_15 AC 12 ms
21,780 KB
testcase_16 AC 9 ms
15,684 KB
testcase_17 AC 14 ms
23,792 KB
testcase_18 AC 23 ms
40,188 KB
testcase_19 AC 7 ms
11,596 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 24 ms
42,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[1000][10001];
int main() {
  int n;
  cin>>n;
  int y[n];
  for (int i=0; i<n; i++) cin>>y[i];
  for (int i=0; i<n; i++) {
    for (int j=0; j<10001; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i=0; i<10001; i++) {
    dp[0][i] = abs(i - y[0]);
  }
  for (int i=1; i<n; i++) {
    dp[i][0] = dp[i-1][0] + y[i];
    int min_v = dp[i-1][0];
    for (int j=1; j<10001; j++) {
      min_v = min(dp[i-1][j], min_v);
      dp[i][j] = min_v + abs(y[i] - j);
    }
  }
  // for (int i=0; i<n; i++) {
  //   for (int j=0; j<10; j++) {
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  int ans = 1e9;
  for (int i=0; i<10001; i++) {
    ans = min(dp[n-1][i], ans);
  }
  cout<<ans<<endl;
}
0