結果
問題 |
No.2036 Max Middle
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:22:40 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 819 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 279,952 KB |
最終ジャッジ日時 | 2025-06-12 13:26:01 |
合計ジャッジ時間 | 4,499 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 TLE * 1 -- * 12 |
ソースコード
from collections import deque n = int(input()) a = list(map(int, input().split())) queue = deque() # Find initial peaks (0-based index) 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: i = queue.popleft() # Check if i is still a valid peak if i < 1 or i >= n-1: continue left = a[i-1] current = a[i] right = a[i+1] if left < current and current > right: # Perform the operation new_val = min(left, right) - 1 a[i] = new_val count += 1 # Check neighboring positions for new peaks for j in [i-1, i+1]: if 0 < j < n-1: # Check if j is a peak if a[j-1] < a[j] and a[j] > a[j+1]: queue.append(j) print(count)