結果

問題 No.2036 Max Middle
ユーザー gew1fw
提出日時 2025-06-12 19:07:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 711 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,332 KB
実行使用メモリ 53,888 KB
最終ジャッジ日時 2025-06-12 19:07:49
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    if n < 3:
        print(0)
        return
    q = deque()
    for i in range(n-2):
        if a[i] < a[i+1] and a[i+1] > a[i+2]:
            q.append(i)
    count = 0
    while q:
        i = q.popleft()
        if i < 0 or i >= n-2:
            continue
        if a[i] < a[i+1] and a[i+1] > a[i+2]:
            count += 1
            new_val = min(a[i], a[i+2]) - 1
            a[i+1] = new_val
            for next_i in [i-1, i+1]:
                if 0 <= next_i <= n-3:
                    q.append(next_i)
    print(count)

if __name__ == "__main__":
    main()
0