結果

問題 No.595 登山
ユーザー 0x19f0x19f
提出日時 2017-11-11 01:40:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 88 ms / 1,500 ms
コード長 549 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 161,736 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-05-03 15:15:50
合計ジャッジ時間 3,832 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 61 ms
7,680 KB
testcase_05 AC 19 ms
5,376 KB
testcase_06 AC 53 ms
6,940 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 54 ms
7,040 KB
testcase_10 AC 38 ms
5,760 KB
testcase_11 AC 33 ms
5,504 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 40 ms
7,936 KB
testcase_15 AC 40 ms
7,936 KB
testcase_16 AC 40 ms
7,808 KB
testcase_17 AC 41 ms
7,808 KB
testcase_18 AC 41 ms
7,936 KB
testcase_19 AC 86 ms
7,936 KB
testcase_20 AC 85 ms
7,936 KB
testcase_21 AC 86 ms
7,936 KB
testcase_22 AC 87 ms
8,064 KB
testcase_23 AC 87 ms
7,808 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 88 ms
7,936 KB
testcase_27 AC 65 ms
8,064 KB
testcase_28 AC 65 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;

ll N, P, H[200000];

int main(void) {
  cin >> N >> P;
  REP(i, 0, N) cin >> H[i];

  vector<ll> dp1(N), dp2(N);
  dp1[0] = 0;
  dp2[0] = INF;
  REP(i, 1, N) {
    dp1[i] = min(min(dp1[i - 1], dp2[i - 1]) + P, dp1[i - 1] + max(H[i] - H[i - 1], 0LL));
    dp2[i] = min(min(dp1[i - 1], dp2[i - 1]) + P, dp2[i - 1] + max(H[i - 1] - H[i], 0LL));
  }
  cout << min(dp1[N - 1], dp2[N - 1]) << endl;
}
0