結果
問題 |
No.2036 Max Middle
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:28:16 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 825 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 81,924 KB |
実行使用メモリ | 280,524 KB |
最終ジャッジ日時 | 2025-04-16 15:31:37 |
合計ジャッジ時間 | 5,081 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 TLE * 1 -- * 12 |
ソースコード
from collections import deque n = int(input()) A = list(map(int, input().split())) queue = deque() # Initialize the queue with all initial peaks for i in range(1, n - 1): if A[i - 1] < A[i] and A[i] > A[i + 1]: queue.append(i) count = 0 while queue: pos = queue.popleft() # Check if the current position is still a peak if pos < 1 or pos >= n - 1: continue if A[pos - 1] >= A[pos] or A[pos] <= A[pos + 1]: continue # Perform the operation m = min(A[pos - 1], A[pos + 1]) - 1 A[pos] = m count += 1 # Check neighboring positions for new peaks for delta in (-1, 1): new_pos = pos + delta if 1 <= new_pos < n - 1: if A[new_pos - 1] < A[new_pos] and A[new_pos] > A[new_pos + 1]: queue.append(new_pos) print(count)