結果
| 問題 | 
                            No.1950 片道きゃっちぼーる
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-05-22 01:16:37 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 843 ms / 3,000 ms | 
| コード長 | 627 bytes | 
| コンパイル時間 | 155 ms | 
| コンパイル使用メモリ | 81,920 KB | 
| 実行使用メモリ | 195,280 KB | 
| 最終ジャッジ日時 | 2024-09-20 12:14:40 | 
| 合計ジャッジ時間 | 13,794 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
from heapq import heapify, heappop, heappush
from collections import defaultdict
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)
Heap = [(-X[i] - A[i], i) for i in range(n)]
heapify(Heap)
Dist = [-1 for _ in range(n)]
while Heap:
    l, curr = heappop(Heap)
    l *= -1
    if Dist[curr] != -1:
        continue
    Dist[curr] = l
    for np in D[X[curr]]:
        if Dist[np] != -1:
            continue
        heappush(Heap, (-l, np))
for i in range(n):
    print(Dist[i] - X[i])