結果

問題 No.2036 Max Middle
ユーザー shauuebbitshauuebbit
提出日時 2022-09-06 00:55:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 773 bytes
コンパイル時間 2,927 ms
コンパイル使用メモリ 204,060 KB
実行使用メモリ 8,980 KB
最終ジャッジ日時 2023-08-13 08:33:48
合計ジャッジ時間 7,088 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,652 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

constexpr long long INF = 1ll << 60;

using namespace std;

int main() {
    int N;
    cin >> N;
    
    vector<long long> A(N, INF);
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    priority_queue<int> pq;

    for (int i = 1; i < N - 1; i++) {
        if (A[i - 1] < A[i] && A[i] > A[i + 1]) pq.push(i);
    }

    int ans = 0;

    while (!pq.empty()) {
        int i = pq.top();
        pq.pop();

        ++ans;

        A[i] = min(A[i - 1], A[i + 1]) - 1;

        if (i > 1) {
            if (A[i - 2] < A[i - 1] && A[i - 1] > A[i]) pq.push(i - 1);
        }

        if (i < N - 2) {
            if (A[i] < A[i + 1] && A[i + 1] > A[i + 2]) pq.push(i + 1);
        }
    }

    cout << ans << endl;

    return 0;
}
0