結果

問題 No.595 登山
コンテスト
ユーザー rabimea
提出日時 2025-09-28 11:40:25
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 13 ms / 1,500 ms
+ 857µs
コード長 745 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,078 ms
コンパイル使用メモリ 331,848 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-15 07:38:49
合計ジャッジ時間 4,390 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>

using std::cin, std::cout, std::cerr;
using ll = long long;

int main() {
    std::ios::sync_with_stdio(false);
    int n, p; cin >> n >> p;
    std::vector<int> a(n);
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    ll inf = 1e18L;
    ll f[2] = {0, inf};
    for(int i = 1; i < n; i ++) {
        ll g[2] = {inf, inf};
        g[0] = g[1] = std::min(f[0], f[1]) + p;
        g[0] = std::min(g[0], f[0] + std::max(0, a[i] - a[i - 1]));
        g[1] = std::min(g[1], f[1] + std::max(0, a[i - 1] - a[i]));

        f[0] = g[0];
        f[1] = g[1];
    }
    cout << std::min(f[0], f[1]) << '\n';
}
0