結果

問題 No.595 登山
ユーザー mayoko_mayoko_
提出日時 2017-11-29 22:46:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 1,500 ms
コード長 708 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 69,772 KB
実行使用メモリ 8,060 KB
最終ジャッジ日時 2023-08-18 13:50:51
合計ジャッジ時間 2,973 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 57 ms
7,580 KB
testcase_05 AC 17 ms
4,500 KB
testcase_06 AC 49 ms
6,664 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 9 ms
4,384 KB
testcase_09 AC 50 ms
7,056 KB
testcase_10 AC 35 ms
5,820 KB
testcase_11 AC 32 ms
5,412 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 AC 38 ms
7,720 KB
testcase_15 AC 38 ms
7,772 KB
testcase_16 AC 38 ms
7,776 KB
testcase_17 AC 37 ms
7,892 KB
testcase_18 AC 38 ms
8,060 KB
testcase_19 AC 79 ms
7,848 KB
testcase_20 AC 78 ms
7,736 KB
testcase_21 AC 79 ms
8,024 KB
testcase_22 AC 79 ms
7,792 KB
testcase_23 AC 79 ms
7,848 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 81 ms
7,796 KB
testcase_27 AC 61 ms
7,900 KB
testcase_28 AC 60 ms
7,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

ll dp[222222][2];

int main() {
    int N;
    ll P;
    cin >> N >> P;
    vector<ll> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    ll INF = 1ll * 100000 * 100000 * 100000 * 1000;
    dp[0][1] = P;
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            int nj = j^1;
            ll diff = (j == 0 ? H[i] - H[i-1] : H[i-1] - H[i]);
            diff = max(0ll, diff);
            ll d1 = dp[i-1][j] + min<ll>(P, diff);
            ll d2 = dp[i-1][nj] + P;
            dp[i][j] = min(d1, d2);
        }
    }
    cout << min(dp[N-1][0], dp[N-1][1]) << endl;
    return 0;
}
0