結果

問題 No.1077 Noelちゃんと星々4
ユーザー kk
提出日時 2020-09-02 15:07:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 201,104 KB
実行使用メモリ 42,592 KB
最終ジャッジ日時 2024-05-01 10:32:21
合計ジャッジ時間 2,902 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 24 ms
31,936 KB
testcase_03 AC 28 ms
38,676 KB
testcase_04 AC 10 ms
14,660 KB
testcase_05 AC 8 ms
12,116 KB
testcase_06 AC 11 ms
17,980 KB
testcase_07 AC 13 ms
19,708 KB
testcase_08 AC 10 ms
15,576 KB
testcase_09 AC 10 ms
13,984 KB
testcase_10 AC 29 ms
39,416 KB
testcase_11 AC 19 ms
26,760 KB
testcase_12 AC 16 ms
23,220 KB
testcase_13 AC 8 ms
11,420 KB
testcase_14 AC 28 ms
37,784 KB
testcase_15 AC 15 ms
21,508 KB
testcase_16 AC 10 ms
15,420 KB
testcase_17 AC 17 ms
23,956 KB
testcase_18 AC 29 ms
38,948 KB
testcase_19 AC 8 ms
11,324 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 33 ms
42,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int n;
int y[1000];
int dp[1000][10000+1];


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  REP (i, n) cin >> y[i];

  for (int h = 0; h <= 10000; h++)
    dp[0][h] = abs(h - y[0]);

  for (int i = 1; i < n; i++) {
    for (int h = 0; h <= 10000; h++) {
      dp[i][h] = dp[i-1][h] + abs(h - y[i]);
      if (h > 0) {
        if (y[i] > h-1)
          dp[i][h] = min(dp[i][h], dp[i][h-1] - 1);
        else
          dp[i][h] = min(dp[i][h], dp[i][h-1] + 1);
      }
    }
  }

  int ret = 1<<30;
  for (int h = 0; h <= 10000; h++)
    ret = min(ret, dp[n-1][h]);
  cout << ret << endl;
  
  return 0;
}
0