結果
| 問題 |
No.1868 Teleporting Cyanmond
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-29 08:19:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 336 ms / 2,000 ms |
| コード長 | 678 bytes |
| コンパイル時間 | 204 ms |
| コンパイル使用メモリ | 82,460 KB |
| 実行使用メモリ | 94,396 KB |
| 最終ジャッジ日時 | 2024-12-29 08:19:29 |
| 合計ジャッジ時間 | 7,818 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
import heapq
N = int(input())
A = list(map(int,input().split()))
A = sorted([(i+1,A[i]) for i in range(N-1)],key=lambda x:x[1])
INFTY = 10**6
dp = [INFTY for _ in range(N+1)]
dp[N] = 0
heap1 = []
heap2 = [(-N,dp[N])]
for j in range(N-2,-1,-1):
i,r = A[j]
while heap2:
if -heap2[0][0]>r:
heapq.heappop(heap2)
elif i+1<=-heap2[0][0]<=r:
k,v = heapq.heappop(heap2)
k = -k
heapq.heappush(heap1,(v,k))
else:break
while heap1 and heap1[0][1]>r:
heapq.heappop(heap1)
dp[i] = dp[i+1]+1
if heap1:
dp[i] = min(heap1[0][0]+1,dp[i])
heapq.heappush(heap2,(-i,dp[i]))
print(dp[1])