結果

問題 No.595 登山
ユーザー 0w10w1
提出日時 2017-11-20 11:55:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 1,500 ms
コード長 654 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 199,792 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-05-04 15:06:18
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,784 KB
testcase_01 AC 2 ms
6,528 KB
testcase_02 AC 2 ms
6,784 KB
testcase_03 AC 3 ms
6,528 KB
testcase_04 AC 21 ms
7,380 KB
testcase_05 AC 8 ms
6,784 KB
testcase_06 AC 18 ms
7,400 KB
testcase_07 AC 5 ms
6,656 KB
testcase_08 AC 5 ms
6,912 KB
testcase_09 AC 19 ms
7,296 KB
testcase_10 AC 13 ms
7,012 KB
testcase_11 AC 12 ms
6,912 KB
testcase_12 AC 4 ms
6,784 KB
testcase_13 AC 8 ms
6,784 KB
testcase_14 AC 17 ms
7,400 KB
testcase_15 AC 17 ms
7,412 KB
testcase_16 AC 17 ms
7,424 KB
testcase_17 AC 17 ms
7,296 KB
testcase_18 AC 15 ms
7,424 KB
testcase_19 AC 26 ms
7,268 KB
testcase_20 AC 26 ms
7,396 KB
testcase_21 AC 25 ms
7,408 KB
testcase_22 AC 25 ms
7,424 KB
testcase_23 AC 26 ms
7,388 KB
testcase_24 AC 3 ms
6,528 KB
testcase_25 AC 3 ms
6,656 KB
testcase_26 AC 27 ms
7,280 KB
testcase_27 AC 20 ms
7,296 KB
testcase_28 AC 20 ms
7,296 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