結果
問題 |
No.2036 Max Middle
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:58:26 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,117 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 55,220 KB |
最終ジャッジ日時 | 2025-06-12 18:58:33 |
合計ジャッジ時間 | 4,774 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 TLE * 1 -- * 12 |
ソースコード
import sys from collections import deque def main(): N, *rest = map(int, sys.stdin.read().split()) A = rest[:N] is_peak = [False] * N q = deque() for j in range(1, N-1): if A[j-1] < A[j] and A[j] > A[j+1]: is_peak[j] = True q.append(j) count = 0 while q: j = q.popleft() if not is_peak[j]: continue # Perform the operation m = min(A[j-1], A[j+1]) - 1 A[j] = m count += 1 is_peak[j] = False # This peak is now processed # Check j-1, j, j+1 for possible new peaks for k in [j-1, j, j+1]: if 1 <= k <= N-2: # Check if k is a peak now is_p = (A[k-1] < A[k] and A[k] > A[k+1]) if is_p: if not is_peak[k]: is_peak[k] = True q.append(k) else: if is_peak[k]: is_peak[k] = False # No longer a peak print(count) if __name__ == "__main__": main()