結果

問題 No.2036 Max Middle
ユーザー rogi52rogi52
提出日時 2022-08-12 22:33:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 643 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 207,284 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-24 10:49:13
合計ジャッジ時間 5,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 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>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

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

    int ans = 0;
    while(!q.empty()) {
        int i = q.front(); q.pop();
        A[i] = min(A[i - 1], A[i + 1]) - 1; ans++;
        if(0 <= i - 2 && A[i - 2] < A[i - 1]) q.push(i - 1);
        if(i + 2 < N && A[i + 1] > A[i + 2]) q.push(i + 1); 
    }

    cout << ans << endl;
}
0