結果

問題 No.1170 Never Want to Walk
ユーザー nishigakenishigake
提出日時 2022-05-30 00:48:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 1,403 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 102,532 KB
最終ジャッジ日時 2023-10-21 00:15:15
合計ジャッジ時間 9,788 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,596 KB
testcase_01 AC 40 ms
53,596 KB
testcase_02 AC 40 ms
53,596 KB
testcase_03 AC 41 ms
53,596 KB
testcase_04 AC 39 ms
53,596 KB
testcase_05 AC 39 ms
53,596 KB
testcase_06 AC 39 ms
53,596 KB
testcase_07 AC 39 ms
53,596 KB
testcase_08 AC 38 ms
53,596 KB
testcase_09 AC 40 ms
53,596 KB
testcase_10 AC 40 ms
53,596 KB
testcase_11 AC 40 ms
53,596 KB
testcase_12 AC 79 ms
75,224 KB
testcase_13 AC 80 ms
75,196 KB
testcase_14 AC 80 ms
75,196 KB
testcase_15 AC 78 ms
75,232 KB
testcase_16 AC 81 ms
75,216 KB
testcase_17 AC 80 ms
75,200 KB
testcase_18 AC 72 ms
73,176 KB
testcase_19 AC 80 ms
75,220 KB
testcase_20 AC 80 ms
75,196 KB
testcase_21 AC 80 ms
75,224 KB
testcase_22 AC 80 ms
75,208 KB
testcase_23 AC 80 ms
75,196 KB
testcase_24 AC 78 ms
75,200 KB
testcase_25 AC 79 ms
75,208 KB
testcase_26 AC 79 ms
75,192 KB
testcase_27 AC 489 ms
102,388 KB
testcase_28 AC 580 ms
101,024 KB
testcase_29 AC 621 ms
102,532 KB
testcase_30 AC 491 ms
102,432 KB
testcase_31 AC 525 ms
102,400 KB
testcase_32 AC 367 ms
102,340 KB
testcase_33 AC 419 ms
101,812 KB
testcase_34 AC 437 ms
101,536 KB
testcase_35 AC 401 ms
102,360 KB
testcase_36 AC 424 ms
101,280 KB
testcase_37 AC 413 ms
101,028 KB
testcase_38 AC 418 ms
101,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right

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

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

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

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

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

    def size(self, x):
        return -self.parents[self.root(x)]

    def issame(self, x, y):
        return self.root(x) == self.root(y)

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

uf = UnionFind(N)
for i in range(N):
    l = bisect_left(X, X[i]-B)
    r = bisect_right(X, X[i]-A)
    for j in range(l, r):
        if uf.issame(i, j):
            break
        uf.unite(i, j)
    for j in range(r-1, l-1, -1):
        if uf.issame(i, j):
            break
        uf.unite(i, j)

    l = bisect_left(X, X[i]+A)
    r = bisect_right(X, X[i]+B)
    for j in range(l, r):
        if uf.issame(i, j):
            break
        uf.unite(i, j)
    for j in range(r-1, l-1, -1):
        if uf.issame(i, j):
            break
        uf.unite(i, j)

for i in range(N):
    print(uf.size(i))
0