結果

問題 No.1170 Never Want to Walk
ユーザー nishigakenishigake
提出日時 2022-05-30 00:27:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 101,560 KB
最終ジャッジ日時 2023-10-21 00:14:53
合計ジャッジ時間 6,772 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,616 KB
testcase_01 AC 38 ms
53,616 KB
testcase_02 AC 36 ms
53,616 KB
testcase_03 AC 36 ms
53,616 KB
testcase_04 AC 40 ms
53,616 KB
testcase_05 AC 35 ms
53,616 KB
testcase_06 AC 35 ms
53,616 KB
testcase_07 AC 35 ms
53,616 KB
testcase_08 AC 35 ms
53,616 KB
testcase_09 AC 35 ms
53,616 KB
testcase_10 AC 35 ms
53,616 KB
testcase_11 AC 35 ms
53,616 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 62 ms
72,140 KB
testcase_25 AC 60 ms
72,136 KB
testcase_26 AC 62 ms
72,144 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 246 ms
101,228 KB
testcase_33 AC 249 ms
101,052 KB
testcase_34 AC 252 ms
101,520 KB
testcase_35 AC 251 ms
101,492 KB
testcase_36 AC 248 ms
101,212 KB
testcase_37 WA -
testcase_38 AC 248 ms
101,560 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(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