結果

問題 No.595 登山
ユーザー PachicobuePachicobue
提出日時 2017-11-10 23:32:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,376 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 170,400 KB
実行使用メモリ 7,044 KB
最終ジャッジ日時 2024-05-03 14:41:52
合計ジャッジ時間 3,304 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 26 ms
7,040 KB
testcase_27 AC 22 ms
6,948 KB
testcase_28 AC 22 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 64;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll P;
    cin >> N >> P;
    vector<ll> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    vector<ll> point;
    bool falling = true;
    for (int i = 0; i < N - 1; i++) {
        if (falling and H[i + 1] > H[i]) {
            point.push_back(H[i]);
            falling = false;
        } else if ((not falling) and H[i + 1] < H[i]) {
            point.push_back(H[i]);
            falling = true;
        }
    }
    point.push_back(H[N - 1]);
    const int size = point.size();
    ll sum = 0;
    for (int i = 0; i < size - 1; i++) {
        if (i % 2 == 0) {
            sum += min(P, point[i + 1] - point[i]);
        }
    }
    cout << sum << endl;

    return 0;
}
0