結果

問題 No.1950 片道きゃっちぼーる
ユーザー rlangevinrlangevin
提出日時 2022-08-29 19:30:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 179,976 KB
最終ジャッジ日時 2024-04-24 09:47:22
合計ジャッジ時間 8,963 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,888 KB
testcase_01 AC 40 ms
54,144 KB
testcase_02 AC 39 ms
54,144 KB
testcase_03 AC 272 ms
168,716 KB
testcase_04 AC 265 ms
168,848 KB
testcase_05 AC 40 ms
53,888 KB
testcase_06 AC 204 ms
147,628 KB
testcase_07 AC 246 ms
175,196 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 250 ms
157,292 KB
testcase_12 AC 267 ms
160,408 KB
testcase_13 AC 262 ms
166,852 KB
testcase_14 AC 246 ms
166,576 KB
testcase_15 WA -
testcase_16 AC 217 ms
148,952 KB
testcase_17 WA -
testcase_18 AC 285 ms
169,368 KB
testcase_19 WA -
testcase_20 AC 258 ms
160,528 KB
testcase_21 AC 265 ms
167,068 KB
testcase_22 AC 264 ms
167,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

N = int(input())
X = list(map(int, input().split()))
A = list(map(int, input().split()))
D = defaultdict(lambda:-1)
for i in range(N):
    D[X[i]] = i
    
T = UnionFind(N)
for i in range(N):
    if D[X[i] + A[i]] != -1:
        T.union(i, D[X[i] + A[i]])
    if D[X[i] - A[i]] != -1:
        T.union(i, D[X[i] - A[i]])
        
M = [0] * N
for i in range(N):
    now = T.find(i)
    M[now] = max(M[now], X[i] + A[i])
    
for i in range(N):
    print(M[T.find(i)] - X[i])
    

0