結果

問題 No.1950 片道きゃっちぼーる
ユーザー rlangevin
提出日時 2023-06-05 22:35:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 964 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 530,456 KB
最終ジャッジ日時 2024-12-29 06:28:19
合計ジャッジ時間 34,339 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 2 TLE * 6 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    return dist

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