結果

問題 No.1950 片道きゃっちぼーる
ユーザー terasaterasa
提出日時 2022-05-22 00:46:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,582 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 81,804 KB
実行使用メモリ 179,724 KB
最終ジャッジ日時 2023-10-20 16:42:15
合計ジャッジ時間 11,704 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,856 KB
testcase_01 AC 40 ms
55,856 KB
testcase_02 AC 41 ms
55,856 KB
testcase_03 AC 470 ms
179,280 KB
testcase_04 AC 464 ms
179,528 KB
testcase_05 AC 40 ms
55,856 KB
testcase_06 AC 451 ms
155,484 KB
testcase_07 AC 271 ms
144,308 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 448 ms
151,440 KB
testcase_12 AC 441 ms
151,444 KB
testcase_13 AC 454 ms
176,560 KB
testcase_14 AC 476 ms
176,036 KB
testcase_15 WA -
testcase_16 AC 468 ms
175,584 KB
testcase_17 WA -
testcase_18 AC 378 ms
179,676 KB
testcase_19 WA -
testcase_20 AC 300 ms
154,016 KB
testcase_21 AC 481 ms
178,476 KB
testcase_22 AC 463 ms
178,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict, Counter

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


class UnionFind:
    def __init__(self, N, X, A):
        self.N = N
        self.par = [-1] * N
        self.m = [x + a for x, a in zip(X, A)]

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if x > y:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x

        self.m[x] = max(self.m[x], self.m[y])
        return True

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

    def size(self, x):
        return -self.par[self.find(x)]

    def roots(self):
        return [i for i in range(self.N) if self.par[i] < 0]

    def members(self, x):
        p = self.find(x)
        return [i for i in range(self.N) if self.find(i) == p]


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

D = {}
for i, x in enumerate(X):
    D[x] = i

uf = UnionFind(N, X, A)
for i, (x, a) in enumerate(zip(X, A)):
    l, r = x - a, x + a
    li, ri = D.get(l), D.get(r)
    if li is not None:
        uf.unite(li, i)
    if ri is not None:
        uf.unite(ri, i)

for i, x in enumerate(X):
    p = uf.find(i)
    print(uf.m[p] - x)
0