結果

問題 No.2036 Max Middle
ユーザー NPNP
提出日時 2024-05-13 11:27:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 527 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,072 KB
実行使用メモリ 145,984 KB
最終ジャッジ日時 2024-12-20 09:24:55
合計ジャッジ時間 33,507 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,292 KB
testcase_01 AC 39 ms
145,984 KB
testcase_02 AC 40 ms
58,632 KB
testcase_03 AC 40 ms
60,840 KB
testcase_04 AC 42 ms
59,092 KB
testcase_05 AC 40 ms
61,492 KB
testcase_06 AC 40 ms
60,580 KB
testcase_07 AC 38 ms
61,424 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 284 ms
82,324 KB
testcase_15 AC 205 ms
82,704 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 86 ms
102,708 KB
testcase_19 TLE -
testcase_20 TLE -
権限があれば一括ダウンロードができます

ソースコード

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:
        i = peaks.pop()
        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) and j not in peaks:
                peaks.append(j)

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

print(result)
0