結果
| 問題 |
No.2036 Max Middle
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:38:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 819 bytes |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 82,360 KB |
| 実行使用メモリ | 279,632 KB |
| 最終ジャッジ日時 | 2025-06-12 18:38:34 |
| 合計ジャッジ時間 | 4,625 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)
gew1fw