結果
問題 |
No.2036 Max Middle
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:31:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 800 bytes |
コンパイル時間 | 496 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 277,600 KB |
最終ジャッジ日時 | 2025-04-16 15:36:44 |
合計ジャッジ時間 | 4,568 ms |
ジャッジサーバーID (参考情報) |
judge4 / 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() # 初始化队列,找到所有初始的峰的位置 for j in range(1, n - 1): if A[j-1] < A[j] and A[j] > A[j+1]: queue.append(j) count = 0 while queue: j = queue.popleft() # 检查当前j是否有效并满足峰的条件 if j < 1 or j >= len(A) - 1: continue if not (A[j-1] < A[j] and A[j] > A[j+1]): continue # 执行操作 min_val = min(A[j-1], A[j+1]) A[j] = min_val - 1 count += 1 # 检查相邻的位置是否形成新的峰 for neighbor in [j-1, j+1]: if 1 <= neighbor <= len(A) - 2: if A[neighbor-1] < A[neighbor] and A[neighbor] > A[neighbor+1]: queue.append(neighbor) print(count)