結果

問題 No.2036 Max Middle
ユーザー Ekiben542Ekiben542
提出日時 2024-05-13 11:33:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 641 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 207,508 KB
最終ジャッジ日時 2024-05-13 11:33:17
合計ジャッジ時間 4,637 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
59,876 KB
testcase_01 AC 33 ms
52,932 KB
testcase_02 AC 31 ms
52,188 KB
testcase_03 AC 31 ms
52,892 KB
testcase_04 AC 30 ms
53,956 KB
testcase_05 AC 29 ms
53,220 KB
testcase_06 AC 29 ms
54,044 KB
testcase_07 AC 30 ms
53,332 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 #

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