結果

問題 No.2036 Max Middle
ユーザー lam6er
提出日時 2025-03-31 17:44:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 785 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 55,096 KB
最終ジャッジ日時 2025-03-31 17:45:05
合計ジャッジ時間 4,573 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    input = sys.stdin.read().split()
    N = int(input[0])
    A = list(map(int, input[1:N+1]))
    queue = deque()

    # Find initial peaks
    for i in range(N-2):
        if A[i] < A[i+1] and A[i+1] > A[i+2]:
            queue.append(i)

    ans = 0

    while queue:
        i = queue.popleft()
        if A[i] < A[i+1] and A[i+1] > A[i+2]:
            ans += 1
            min_val = min(A[i], A[i+2])
            A[i+1] = min_val - 1
            # Check the affected regions
            for dj in [-1, 0, 1]:
                j = i + dj
                if 0 <= j < N-2:
                    if A[j] < A[j+1] and A[j+1] > A[j+2]:
                        queue.append(j)
    
    print(ans)

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