結果

問題 No.1950 片道きゃっちぼーる
ユーザー lloyzlloyz
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,888 KB
testcase_01 AC 43 ms
53,888 KB
testcase_02 AC 43 ms
54,144 KB
testcase_03 AC 573 ms
163,156 KB
testcase_04 AC 595 ms
163,284 KB
testcase_05 AC 42 ms
53,888 KB
testcase_06 AC 443 ms
137,360 KB
testcase_07 AC 432 ms
194,716 KB
testcase_08 AC 634 ms
195,280 KB
testcase_09 AC 625 ms
167,232 KB
testcase_10 AC 706 ms
174,932 KB
testcase_11 AC 676 ms
187,244 KB
testcase_12 AC 684 ms
187,860 KB
testcase_13 AC 602 ms
148,820 KB
testcase_14 AC 577 ms
152,132 KB
testcase_15 AC 843 ms
170,584 KB
testcase_16 AC 457 ms
135,804 KB
testcase_17 AC 41 ms
54,144 KB
testcase_18 AC 624 ms
183,512 KB
testcase_19 AC 796 ms
170,324 KB
testcase_20 AC 510 ms
167,012 KB
testcase_21 AC 614 ms
153,684 KB
testcase_22 AC 577 ms
153,312 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