結果

問題 No.1950 片道きゃっちぼーる
ユーザー noriocnorioc
提出日時 2022-05-21 00:26:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,288 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 11,856 KB
実行使用メモリ 106,484 KB
最終ジャッジ日時 2023-10-20 15:14:55
合計ジャッジ時間 23,364 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,220 KB
testcase_01 AC 28 ms
10,220 KB
testcase_02 AC 29 ms
10,220 KB
testcase_03 AC 1,057 ms
103,336 KB
testcase_04 AC 1,056 ms
103,344 KB
testcase_05 AC 30 ms
10,220 KB
testcase_06 AC 1,034 ms
97,264 KB
testcase_07 AC 789 ms
103,332 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 995 ms
103,604 KB
testcase_12 AC 977 ms
103,604 KB
testcase_13 AC 1,056 ms
98,516 KB
testcase_14 AC 1,072 ms
98,064 KB
testcase_15 WA -
testcase_16 AC 1,075 ms
97,364 KB
testcase_17 WA -
testcase_18 AC 992 ms
103,656 KB
testcase_19 WA -
testcase_20 AC 854 ms
103,348 KB
testcase_21 AC 1,105 ms
98,200 KB
testcase_22 AC 1,092 ms
99,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.data = [-1] * (n + 1)

    def root(self, a: int) -> int:
        if self.data[a] < 0: return a
        self.data[a] = self.root(self.data[a])
        return self.data[a]

    def unite(self, a: int, b: int) -> bool:
        pa = self.root(a)
        pb = self.root(b)
        if pa == pb: return False
        if self.data[pa] > self.data[pb]:
            pa, pb = pb, pa
        self.data[pa] += self.data[pb] # pa を pb をつなげる
        self.data[pb] = pa
        return True

    def issame(self, a: int, b: int) -> bool:
        return self.root(a) == self.root(b)

    def size(self, a: int) -> int:
        """a が属する集合のサイズ"""
        return -self.data[self.root(a)]


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

x2i = {}
for i in range(N):
    x2i[X[i]] = i

uf = UnionFind(N)

for i, a in enumerate(A):
    for s in (1, -1):
        x = X[i] + a * s
        if x in x2i:
            j = x2i[x]
            uf.unite(i, j)

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

m = {i: X[i] + A[i] for i in range(N)}
for d, i in xs:
    root = uf.root(i)
    m[root] = max(m[root], m[i])

for i in range(N):
    print(m[uf.root(i)] - X[i])
0