結果

問題 No.1077 Noelちゃんと星々4
ユーザー closeknclosekn
提出日時 2020-06-13 12:21:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 164,968 KB
実行使用メモリ 81,572 KB
最終ジャッジ日時 2023-09-07 05:53:11
合計ジャッジ時間 2,983 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,396 KB
testcase_02 AC 27 ms
56,968 KB
testcase_03 AC 34 ms
72,836 KB
testcase_04 AC 12 ms
24,516 KB
testcase_05 AC 10 ms
19,036 KB
testcase_06 AC 15 ms
30,480 KB
testcase_07 AC 16 ms
34,800 KB
testcase_08 AC 11 ms
26,276 KB
testcase_09 AC 11 ms
22,900 KB
testcase_10 AC 34 ms
72,896 KB
testcase_11 AC 22 ms
48,412 KB
testcase_12 AC 19 ms
40,320 KB
testcase_13 AC 10 ms
18,184 KB
testcase_14 AC 33 ms
71,396 KB
testcase_15 AC 18 ms
39,104 KB
testcase_16 AC 13 ms
26,712 KB
testcase_17 AC 20 ms
44,204 KB
testcase_18 AC 34 ms
74,216 KB
testcase_19 AC 9 ms
17,484 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 37 ms
81,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX_Y = 10004;
const long long INF = 1e12;

int main() {
  int n;
  cin >> n;
  int y[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> y[i];
  }
  if ( n == 1 ) { cout << 0 << endl; return 0; }
  long long dp[n+1][MAX_Y];
  for ( int i = 0; i < n+1; i++ ) {
    for ( int j = 0; j < MAX_Y; j++ ) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  for ( int i = 0; i < n; i++ ) {
    long long mn = INF;
    for ( int j = 0; j < MAX_Y; j++ ) {
      mn = min(mn, dp[i][j]);
      if ( y[i] > j ) {
        dp[i+1][j] = mn + (y[i]-j);
      } else {
        dp[i+1][j] = mn + (j-y[i]);
      }
    }
  }
  
  long long ans = INF;
  for ( int j = 0; j < MAX_Y; j++ ) {
    ans = min(ans, dp[n][j]);
  }
  cout << ans << endl;
  return 0;
}
0