結果

問題 No.1950 片道きゃっちぼーる
ユーザー 👑 KazunKazun
提出日時 2022-05-20 22:24:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 867 ms / 3,000 ms
コード長 517 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 81,656 KB
実行使用メモリ 195,044 KB
最終ジャッジ日時 2023-10-20 13:09:55
合計ジャッジ時間 14,827 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,500 KB
testcase_01 AC 43 ms
55,500 KB
testcase_02 AC 42 ms
55,500 KB
testcase_03 AC 631 ms
162,872 KB
testcase_04 AC 634 ms
162,916 KB
testcase_05 AC 41 ms
55,500 KB
testcase_06 AC 468 ms
136,844 KB
testcase_07 AC 432 ms
194,428 KB
testcase_08 AC 652 ms
195,044 KB
testcase_09 AC 660 ms
166,848 KB
testcase_10 AC 753 ms
174,736 KB
testcase_11 AC 739 ms
186,904 KB
testcase_12 AC 738 ms
187,500 KB
testcase_13 AC 644 ms
148,440 KB
testcase_14 AC 581 ms
151,548 KB
testcase_15 AC 867 ms
169,720 KB
testcase_16 AC 484 ms
135,168 KB
testcase_17 AC 43 ms
55,500 KB
testcase_18 AC 667 ms
183,348 KB
testcase_19 AC 863 ms
169,728 KB
testcase_20 AC 516 ms
166,888 KB
testcase_21 AC 634 ms
152,956 KB
testcase_22 AC 624 ms
152,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heapify, heappop, heappush

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)

Q=[(-(X[i]+A[i]), i) for i in range(N)]
heapify(Q)

T=[-1]*N
while Q:
    d,i=heappop(Q); d=-d

    if T[i]!=-1:
        continue

    T[i]=d
    for j in D[X[i]]:
        if T[j]==-1:
            heappush(Q, (-d, j))

for i in range(N):
    print(T[i]-X[i])
0