結果

問題 No.1950 片道きゃっちぼーる
ユーザー rlangevinrlangevin
提出日時 2023-06-05 22:38:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 173,156 KB
最終ジャッジ日時 2023-08-28 09:45:36
合計ジャッジ時間 12,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,652 KB
testcase_01 AC 89 ms
71,616 KB
testcase_02 AC 89 ms
71,548 KB
testcase_03 AC 358 ms
163,776 KB
testcase_04 AC 474 ms
163,668 KB
testcase_05 AC 92 ms
71,880 KB
testcase_06 AC 303 ms
156,692 KB
testcase_07 AC 313 ms
160,448 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 334 ms
173,156 KB
testcase_12 AC 326 ms
164,360 KB
testcase_13 AC 535 ms
157,792 KB
testcase_14 AC 522 ms
157,268 KB
testcase_15 WA -
testcase_16 AC 329 ms
158,808 KB
testcase_17 WA -
testcase_18 AC 500 ms
163,900 KB
testcase_19 AC 873 ms
159,008 KB
testcase_20 AC 339 ms
160,260 KB
testcase_21 AC 510 ms
157,972 KB
testcase_22 AC 507 ms
158,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
def bfs(G, s, N):
    Q = deque([])
    for u in G[s]:
        seen[u] = seen[s]
        Q.append(u)

    while Q:
        u = Q.popleft()
        for v in G[u]:
            if seen[v] != -1:
                continue
            seen[v] = seen[u]
            Q.append(v)

    return seen

N = int(input())
X = list(map(int, input().split()))
A = list(map(int, input().split()))

G = [[] for i in range(N)]
D = defaultdict(int)
for i in range(N):
    D[X[i]] = i
    
for i in range(N):
    if X[i] + A[i] in D:
        G[D[X[i] + A[i]]].append(i)
    if X[i] - A[i] in D:
        G[D[X[i] - A[i]]].append(i)
        
seen = [-1] * N
L = []
for i in range(N):
    L.append((X[i] + A[i], i))
L.sort(reverse=True)

for d, i in L:
    if seen[i] != -1:
        continue
    seen[i] = d
    bfs(G, i, N)
    
for i in range(N):
    print(seen[i] - X[i])
0