結果

問題 No.1170 Never Want to Walk
ユーザー rei60rei60
提出日時 2020-08-22 12:02:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,617 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 109,064 KB
最終ジャッジ日時 2024-04-23 07:09:27
合計ジャッジ時間 7,992 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
60,556 KB
testcase_01 AC 38 ms
53,112 KB
testcase_02 AC 35 ms
53,092 KB
testcase_03 AC 37 ms
53,540 KB
testcase_04 AC 35 ms
54,352 KB
testcase_05 AC 34 ms
53,420 KB
testcase_06 AC 34 ms
53,332 KB
testcase_07 AC 33 ms
53,892 KB
testcase_08 AC 34 ms
53,744 KB
testcase_09 AC 33 ms
52,528 KB
testcase_10 AC 35 ms
53,816 KB
testcase_11 AC 34 ms
53,076 KB
testcase_12 AC 61 ms
73,068 KB
testcase_13 AC 69 ms
76,248 KB
testcase_14 AC 74 ms
76,372 KB
testcase_15 AC 59 ms
73,384 KB
testcase_16 AC 64 ms
73,616 KB
testcase_17 AC 81 ms
76,400 KB
testcase_18 AC 59 ms
72,864 KB
testcase_19 AC 62 ms
73,380 KB
testcase_20 AC 76 ms
76,292 KB
testcase_21 AC 57 ms
72,940 KB
testcase_22 AC 80 ms
76,516 KB
testcase_23 AC 84 ms
76,428 KB
testcase_24 AC 82 ms
76,276 KB
testcase_25 AC 81 ms
76,576 KB
testcase_26 AC 90 ms
76,692 KB
testcase_27 AC 372 ms
101,524 KB
testcase_28 AC 355 ms
101,744 KB
testcase_29 AC 410 ms
102,588 KB
testcase_30 AC 384 ms
102,084 KB
testcase_31 AC 382 ms
101,964 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(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.find(x)]

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

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

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)

for idx, i in enumerate(X):
    L_left = bisect_left(X, i-B)
    L_right = bisect_right(X, i-A)
    R_left = bisect_left(X, i+A)
    R_right = bisect_right(X, i+B)
    
    for j in range(L_left, L_right):
        uf.union(idx,j)
    for j in range(R_left, R_right):
        uf.union(idx,j)

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