結果

問題 No.2036 Max Middle
コンテスト
ユーザー NP
提出日時 2024-05-13 11:33:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 641 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 115 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 218,356 KB
最終ジャッジ日時 2026-05-27 10:55:08
合計ジャッジ時間 4,263 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def count_operations(N, A):
    def is_peak(i):
        return 0 < i < N - 1 and A[i - 1] < A[i] > A[i + 1]

    peaks = {i for i in range(1, N - 1) if is_peak(i)}
    count = 0

    while peaks:
        to_check = list(peaks)
        for i in to_check:
            if i in peaks:
                peaks.remove(i)
                count += 1
                A[i] = min(A[i - 1], A[i + 1]) - 1
                for j in (i - 1, i + 1):
                    if 0 < j < N - 1 and is_peak(j):
                        peaks.add(j)

    return count

N = int(input())
A = list(map(int, input().split()))
result = count_operations(N, A)

print(result)
0