結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 54 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 33 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 34 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 75 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 78 ms
4,376 KB
testcase_27 AC 57 ms
4,380 KB
testcase_28 AC 57 ms
4,380 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) {
        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);
        a0 = a1; cin >> a1;
    }
    cout << min3(w, r, l) << endl;
    return 0;
}
0