結果

問題 No.595 登山
ユーザー 0w10w1
提出日時 2017-11-20 11:55:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 1,500 ms
コード長 654 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 198,452 KB
実行使用メモリ 7,520 KB
最終ジャッジ日時 2023-08-17 08:16:29
合計ジャッジ時間 3,893 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,508 KB
testcase_01 AC 4 ms
6,492 KB
testcase_02 AC 3 ms
6,576 KB
testcase_03 AC 4 ms
6,472 KB
testcase_04 AC 24 ms
7,520 KB
testcase_05 AC 10 ms
6,684 KB
testcase_06 AC 21 ms
7,132 KB
testcase_07 AC 6 ms
6,704 KB
testcase_08 AC 7 ms
6,648 KB
testcase_09 AC 21 ms
7,292 KB
testcase_10 AC 16 ms
6,940 KB
testcase_11 AC 15 ms
6,884 KB
testcase_12 AC 5 ms
6,528 KB
testcase_13 AC 9 ms
6,724 KB
testcase_14 AC 19 ms
7,260 KB
testcase_15 AC 20 ms
7,264 KB
testcase_16 AC 20 ms
7,460 KB
testcase_17 AC 19 ms
7,420 KB
testcase_18 AC 19 ms
7,264 KB
testcase_19 AC 29 ms
7,308 KB
testcase_20 AC 29 ms
7,252 KB
testcase_21 AC 29 ms
7,308 KB
testcase_22 AC 29 ms
7,240 KB
testcase_23 AC 29 ms
7,240 KB
testcase_24 AC 4 ms
6,524 KB
testcase_25 AC 4 ms
6,456 KB
testcase_26 AC 30 ms
7,288 KB
testcase_27 AC 24 ms
7,316 KB
testcase_28 AC 24 ms
7,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAXN = int(2e5);

int N, P;
int H[MAXN];

long long dpl[MAXN], dpr[MAXN];

signed main() {
  ios::sync_with_stdio(false);
  cin >> N >> P;
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  memset(dpl, 0x3f, sizeof(dpl));
  memset(dpr, 0x3f, sizeof(dpr));
  dpl[0] = dpr[0] = 0;
  for (int i = 1; i < N; ++i) {
    if (i == 1) {
      dpl[i] = P;
    } else {
      dpl[i] = min(dpl[i - 1] + min(P, max(0, H[i - 1] - H[i])), dpr[i - 1] + P);
    }
    dpr[i] = min(dpr[i - 1] + min(P, max(0, H[i] - H[i - 1])), dpl[i - 1] + P);
  }
  cout << min(dpl[N - 1], dpr[N - 1]) << endl;
  return 0;
}
0