結果

問題 No.595 登山
ユーザー tsutajtsutaj
提出日時 2019-08-13 06:09:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 1,500 ms
コード長 882 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 51,996 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-10-19 10:49:00
合計ジャッジ時間 2,345 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 27 ms
7,300 KB
testcase_05 AC 10 ms
5,984 KB
testcase_06 AC 24 ms
6,776 KB
testcase_07 AC 4 ms
4,368 KB
testcase_08 AC 5 ms
4,368 KB
testcase_09 AC 24 ms
6,776 KB
testcase_10 AC 17 ms
6,512 KB
testcase_11 AC 16 ms
6,248 KB
testcase_12 AC 4 ms
4,368 KB
testcase_13 AC 9 ms
5,984 KB
testcase_14 AC 23 ms
7,564 KB
testcase_15 AC 23 ms
7,564 KB
testcase_16 AC 23 ms
7,564 KB
testcase_17 AC 23 ms
7,564 KB
testcase_18 AC 23 ms
7,564 KB
testcase_19 AC 31 ms
7,564 KB
testcase_20 AC 31 ms
7,564 KB
testcase_21 AC 31 ms
7,564 KB
testcase_22 AC 32 ms
7,564 KB
testcase_23 AC 32 ms
7,564 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,368 KB
testcase_26 AC 32 ms
7,564 KB
testcase_27 AC 27 ms
7,564 KB
testcase_28 AC 27 ms
7,564 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++) {
            // fprintf(stderr, "dp[%d][%d] = %lld\n", i+1, x, dp[i][x]);
            for(int y=0; y<2; y++) {
                ll add = P;
                if(x == y and y == 0) add = min(add, max(H[i+1] - H[i], 0LL));
                if(x == y and y == 1) add = min(add, max(H[i] - H[i+1], 0LL));

                dp[i+1][y] = min(dp[i+1][y], dp[i][x] + add);
            }
        }
        // fprintf(stderr, "\n");
    }

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