結果

問題 No.1950 片道きゃっちぼーる
ユーザー first_vilfirst_vil
提出日時 2022-05-20 22:26:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,962 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 133,964 KB
最終ジャッジ日時 2023-10-20 13:11:48
合計ジャッジ時間 9,547 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,540 KB
testcase_01 AC 38 ms
53,540 KB
testcase_02 AC 37 ms
53,540 KB
testcase_03 AC 295 ms
130,772 KB
testcase_04 AC 293 ms
130,904 KB
testcase_05 AC 37 ms
53,540 KB
testcase_06 AC 284 ms
114,184 KB
testcase_07 AC 276 ms
133,620 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 288 ms
133,236 KB
testcase_12 AC 298 ms
133,168 KB
testcase_13 AC 328 ms
108,980 KB
testcase_14 AC 318 ms
108,780 KB
testcase_15 WA -
testcase_16 AC 289 ms
110,100 KB
testcase_17 WA -
testcase_18 AC 318 ms
131,872 KB
testcase_19 WA -
testcase_20 AC 273 ms
133,964 KB
testcase_21 AC 338 ms
130,156 KB
testcase_22 AC 362 ms
130,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
mod = int(1e9 + 7)
# mod = 998244353


class dsu:
    n = 1
    parent_or_size = [-1 for i in range(n)]

    def __init__(self, N):
        self.n = N
        self.parent_or_size = [-1 for i in range(N)]

    def merge(self, a, b):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n)
        x = self.leader(a)
        y = self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n)
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n)
        if self.parent_or_size[a] < 0:
            return a
        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]


from bisect import bisect_left

n = ii()
x = li()
a = li()
uf = dsu(n)
for i in range(n):
    j = bisect_left(x, x[i] - a[i])
    if x[j] == x[i] - a[i]:
        uf.merge(i, j)
    j = bisect_left(x, x[i] + a[i])
    if j < n and x[j] == x[i] + a[i]:
        uf.merge(i, j)

ans = [0] * n
for i in range(n):
    r = uf.leader(i)
    if ans[r] < x[i] + a[i]:
        ans[r] = x[i] + a[i]
for i in range(n):
    print(ans[uf.leader(i)]-x[i])
0