結果

問題 No.1950 片道きゃっちぼーる
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-05-20 21:28:40
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 898 ms / 3,000 ms
コード長 1,411 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 168,800 KB
最終ジャッジ日時 2023-10-20 11:46:31
合計ジャッジ時間 11,329 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,508 KB
testcase_01 AC 41 ms
55,508 KB
testcase_02 AC 41 ms
55,508 KB
testcase_03 AC 296 ms
168,440 KB
testcase_04 AC 377 ms
168,444 KB
testcase_05 AC 40 ms
55,508 KB
testcase_06 AC 251 ms
156,948 KB
testcase_07 AC 236 ms
149,732 KB
testcase_08 AC 769 ms
157,848 KB
testcase_09 AC 314 ms
167,100 KB
testcase_10 AC 486 ms
160,060 KB
testcase_11 AC 269 ms
157,692 KB
testcase_12 AC 279 ms
157,956 KB
testcase_13 AC 441 ms
168,800 KB
testcase_14 AC 446 ms
168,464 KB
testcase_15 AC 898 ms
160,064 KB
testcase_16 AC 260 ms
150,124 KB
testcase_17 AC 41 ms
55,508 KB
testcase_18 AC 399 ms
166,592 KB
testcase_19 AC 891 ms
160,068 KB
testcase_20 AC 265 ms
158,008 KB
testcase_21 AC 440 ms
168,704 KB
testcase_22 AC 406 ms
168,708 KB
権限があれば一括ダウンロードができます

ソースコード

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