結果

問題 No.1950 片道きゃっちぼーる
ユーザー SPD_9X2
提出日時 2022-05-20 21:28:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 865 ms / 3,000 ms
コード長 1,411 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 169,520 KB
最終ジャッジ日時 2024-09-20 07:18:40
合計ジャッジ時間 11,352 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin
from collections import deque

def uf_find(n,p):

    ufl = []

    while p[n] != n:
        ufl.append(n)
        n = p[n]

    for i in ufl:
        p[i] = n

    return n


def uf_union(a,b,p,rank):

    ap = uf_find(a,p)
    bp = uf_find(b,p)

    if ap == bp:
        return True
    else:

        if rank[ap] > rank[bp]:
            p[bp] = ap
        elif rank[ap] < rank[bp]:
            p[ap] = bp
        else:
            p[bp] = ap
            rank[ap] += 1

        return False

N = int(stdin.readline())

X = list(map(int,stdin.readline().split()))
A = list(map(int,stdin.readline().split()))

dic = {}

for i in range(N):
    dic[X[i]] = i

lis = [ [] for i in range(N)]

for i in range(N):

    lx = X[i] - A[i]
    if lx in dic:
        nex = dic[lx]
        lis[nex].append(i)

    lx = X[i] + A[i]
    if lx in dic:
        nex = dic[lx]
        lis[nex].append(i)

q = deque()
    
B = [None for i in range(N)]

wow = [ (X[i]+A[i],i) for i in range(N) ]
wow.sort()
wow.reverse()

for dist,ind in wow:

    if B[ind] == None:
        q.append(ind)
        B[ind] = dist

        while q:
            v = q.popleft()
            for nex in lis[v]:
                if B[nex] == None:
                    B[nex] = B[v]
                    q.append(nex)

#print (B)
ANS  = []
for i in range(N):
    ANS.append(str(B[i]-X[i]))

print ("\n".join(ANS))
0