結果
問題 |
No.2036 Max Middle
|
ユーザー |
![]() |
提出日時 | 2025-03-26 15:56:57 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,221 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 82,080 KB |
実行使用メモリ | 299,272 KB |
最終ジャッジ日時 | 2025-03-26 15:57:19 |
合計ジャッジ時間 | 4,614 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 TLE * 1 -- * 12 |
ソースコード
import sys from collections import deque def main(): N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) peaks = deque() # Find initial peaks (0-based indices) for i in range(N - 2): if A[i] < A[i + 1] and A[i + 1] > A[i + 2]: peaks.append(i + 1) # Peak at position i+1 (0-based) count = 0 while peaks: m = peaks.popleft() left = m - 1 right = m + 1 # Check if current position is still a valid peak if left < 0 or right >= N: continue if A[left] < A[m] and A[m] > A[right]: # Process the peak min_val = min(A[left], A[right]) - 1 A[m] = min_val count += 1 # Check left triplet (m-2, m-1, m) if m - 2 >= 0: new_mid = m - 1 if A[m - 2] < A[new_mid] and A[new_mid] > A[m]: peaks.append(new_mid) # Check right triplet (m, m+1, m+2) if m + 2 < N: new_mid = m + 1 if A[m] < A[new_mid] and A[new_mid] > A[m + 2]: peaks.append(new_mid) print(count) if __name__ == '__main__': main()