結果

問題 No.1950 片道きゃっちぼーる
ユーザー pitPpitP
提出日時 2022-05-21 13:52:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 879 ms / 3,000 ms
コード長 571 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,548 KB
実行使用メモリ 194,964 KB
最終ジャッジ日時 2023-10-20 16:11:26
合計ジャッジ時間 15,204 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,376 KB
testcase_01 AC 41 ms
55,376 KB
testcase_02 AC 42 ms
55,376 KB
testcase_03 AC 634 ms
162,784 KB
testcase_04 AC 633 ms
162,828 KB
testcase_05 AC 41 ms
55,396 KB
testcase_06 AC 473 ms
136,744 KB
testcase_07 AC 446 ms
194,312 KB
testcase_08 AC 678 ms
194,964 KB
testcase_09 AC 661 ms
166,772 KB
testcase_10 AC 764 ms
174,444 KB
testcase_11 AC 732 ms
186,620 KB
testcase_12 AC 719 ms
187,388 KB
testcase_13 AC 631 ms
148,352 KB
testcase_14 AC 585 ms
151,480 KB
testcase_15 AC 879 ms
169,920 KB
testcase_16 AC 496 ms
135,064 KB
testcase_17 AC 42 ms
55,396 KB
testcase_18 AC 659 ms
183,256 KB
testcase_19 AC 873 ms
169,936 KB
testcase_20 AC 545 ms
166,796 KB
testcase_21 AC 652 ms
152,916 KB
testcase_22 AC 611 ms
152,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0