結果

問題 No.595 登山
ユーザー tsutajtsutaj
提出日時 2019-08-13 05:47:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 771 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 51,888 KB
実行使用メモリ 7,592 KB
最終ジャッジ日時 2023-10-19 10:13:50
合計ジャッジ時間 2,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 WA -
testcase_27 AC 27 ms
7,588 KB
testcase_28 AC 27 ms
7,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

ll dp[200010][2];
const ll INF = 1LL << 60;
int main() {
    ll N, P; scanf("%lld%lld", &N, &P);
    vector<ll> H(N);
    for(int i=0; i<N; i++) scanf("%lld", &H[i]);
    
    fill(dp[0], dp[N+1], INF);
    dp[0][0] = 0;

    for(int i=0; i+1<N; i++) {
        for(int x=0; x<2; x++) {
            for(int y=0; y<2; y++) {
                ll add = 0;
                if(x != y) add += P;
                else if(y == 0) add += max(H[i+1] - H[i], 0LL);
                else add += max(H[i] - H[i+1], 0LL);

                dp[i+1][y] = min(dp[i+1][y], dp[i][x] + add);
            }
        }
    }

    printf("%lld\n", min(dp[N-1][0], dp[N-1][1]));
    return 0;
}
0