結果

問題 No.595 登山
ユーザー はむこはむこ
提出日時 2017-04-17 09:37:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 77 ms / 1,500 ms
コード長 739 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 144,048 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-26 10:32:17
合計ジャッジ時間 3,827 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 54 ms
4,380 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 47 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 46 ms
4,380 KB
testcase_10 AC 33 ms
4,376 KB
testcase_11 AC 29 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 34 ms
4,376 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 AC 34 ms
4,380 KB
testcase_18 AC 35 ms
4,376 KB
testcase_19 AC 76 ms
4,380 KB
testcase_20 AC 75 ms
4,380 KB
testcase_21 AC 76 ms
4,376 KB
testcase_22 AC 75 ms
4,380 KB
testcase_23 AC 76 ms
4,500 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 77 ms
4,380 KB
testcase_27 AC 57 ms
4,380 KB
testcase_28 AC 57 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
using ll = long long; 

auto f = [](ll x, ll y, bool b) { return max(0ll, (b ? 1 : -1) * (y - x)); };
auto min3 = [](ll a, ll b, ll c) { return min(a, min(b, c)); };
int main(void) {
    ll n, p; cin >> n >> p;
    ll a0, a1; cin >> a0 >> a1;
    ll w = p, r = f(a0, a1, true), l = f(a0, a1, false) + p;
    ll pw, pr, pl;
    repi(i, 1, n-1) {
        a0 = a1; cin >> a1;
        swap(w, pw); swap(l, pl); swap(r, pr);
        w = p + min3(pw, pr, pl);
        r = min(p, f(a0, a1, true )) + min(pw, pr);
        l = min(p, f(a0, a1, false)) + min(pw, pl);
    }
    cout << min3(w, r, l) << endl;
    return 0;
}
0