結果
| 問題 |
No.2036 Max Middle
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:22:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 825 bytes |
| コンパイル時間 | 344 ms |
| コンパイル使用メモリ | 82,404 KB |
| 実行使用メモリ | 280,296 KB |
| 最終ジャッジ日時 | 2025-04-15 21:28:11 |
| 合計ジャッジ時間 | 4,499 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)
lam6er