結果

問題 No.1950 片道きゃっちぼーる
ユーザー lloyzlloyz
提出日時 2022-05-22 01:16:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 843 ms / 3,000 ms
コード長 627 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 195,152 KB
最終ジャッジ日時 2023-10-20 16:42:40
合計ジャッジ時間 14,741 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,608 KB
testcase_01 AC 40 ms
55,608 KB
testcase_02 AC 40 ms
55,608 KB
testcase_03 AC 608 ms
162,976 KB
testcase_04 AC 619 ms
163,032 KB
testcase_05 AC 40 ms
55,608 KB
testcase_06 AC 461 ms
136,940 KB
testcase_07 AC 428 ms
194,516 KB
testcase_08 AC 660 ms
195,152 KB
testcase_09 AC 635 ms
166,964 KB
testcase_10 AC 734 ms
174,644 KB
testcase_11 AC 699 ms
186,856 KB
testcase_12 AC 697 ms
187,592 KB
testcase_13 AC 606 ms
148,564 KB
testcase_14 AC 573 ms
151,704 KB
testcase_15 AC 840 ms
170,124 KB
testcase_16 AC 485 ms
135,276 KB
testcase_17 AC 39 ms
55,612 KB
testcase_18 AC 662 ms
183,452 KB
testcase_19 AC 843 ms
170,132 KB
testcase_20 AC 527 ms
166,972 KB
testcase_21 AC 646 ms
153,116 KB
testcase_22 AC 617 ms
153,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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