結果

問題 No.595 登山
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-11-12 07:11:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 1,500 ms
コード長 1,724 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 164,164 KB
実行使用メモリ 8,252 KB
最終ジャッジ日時 2023-08-16 10:21:53
合計ジャッジ時間 3,738 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,740 KB
testcase_01 AC 4 ms
7,504 KB
testcase_02 AC 3 ms
7,656 KB
testcase_03 AC 3 ms
7,456 KB
testcase_04 AC 23 ms
8,016 KB
testcase_05 AC 9 ms
7,468 KB
testcase_06 AC 20 ms
7,864 KB
testcase_07 AC 5 ms
7,464 KB
testcase_08 AC 6 ms
7,464 KB
testcase_09 AC 20 ms
7,808 KB
testcase_10 AC 15 ms
7,476 KB
testcase_11 AC 14 ms
7,468 KB
testcase_12 AC 5 ms
7,468 KB
testcase_13 AC 8 ms
7,636 KB
testcase_14 AC 17 ms
8,092 KB
testcase_15 AC 18 ms
8,092 KB
testcase_16 AC 18 ms
8,136 KB
testcase_17 AC 17 ms
8,128 KB
testcase_18 AC 18 ms
8,132 KB
testcase_19 AC 28 ms
8,128 KB
testcase_20 AC 28 ms
8,200 KB
testcase_21 AC 29 ms
8,128 KB
testcase_22 AC 28 ms
8,148 KB
testcase_23 AC 28 ms
8,080 KB
testcase_24 AC 3 ms
7,460 KB
testcase_25 AC 4 ms
7,512 KB
testcase_26 AC 30 ms
8,252 KB
testcase_27 AC 22 ms
8,204 KB
testcase_28 AC 23 ms
8,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



typedef long long ll;
#define INF 1LL<<60
int N; ll P, H[201010];
ll dp[201010][2];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> P;
    rep(i, 0, N) cin >> H[i];

    rep(i, 0, 201010) rep(dir, 0, 2) dp[i][dir] = INF;
    dp[0][0] = 0;

    rep(i, 0, N - 1) {
        // ->を伸ばす遷移
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + min(P, max(H[i + 1] - H[i], 0LL)));
        
        // 今まで->だったのを<-とする遷移
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + P);

        // <-を伸ばす遷移
        dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + min(P, max(H[i] - H[i + 1], 0LL)));

        // 今まで<-だったのを->とする遷移
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + P);
    }

    ll ans = min(dp[N - 1][0], dp[N - 1][1]);
    cout << ans << endl;
}
0