結果
問題 |
No.1950 片道きゃっちぼーる
|
ユーザー |
![]() |
提出日時 | 2022-05-21 13:52:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 876 ms / 3,000 ms |
コード長 | 571 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 195,328 KB |
最終ジャッジ日時 | 2024-09-20 11:44:47 |
合計ジャッジ時間 | 14,844 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
from collections import defaultdict import heapq n = int(input()) x = list(map(int,input().split())) a = list(map(int,input().split())) d = defaultdict(list) for i in range(n): d[x[i] + a[i]].append(i) d[x[i] - a[i]].append(i) hq = [(-x[i]-a[i], i) for i in range(n)] heapq.heapify(hq) dist = [-1] * n while hq: l,now = heapq.heappop(hq) l = -l if dist[now] != -1: continue dist[now] = l for nxt in d[x[now]]: if dist[nxt] != -1:continue heapq.heappush(hq,(-l,nxt)) for i in range(n): print(dist[i] - x[i])