結果

問題 No.1170 Never Want to Walk
ユーザー ntudantuda
提出日時 2021-10-01 23:21:13
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,496 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 110,244 KB
最終ジャッジ日時 2023-09-26 22:24:23
合計ジャッジ時間 11,019 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,528 KB
testcase_01 AC 66 ms
71,416 KB
testcase_02 AC 68 ms
71,308 KB
testcase_03 AC 66 ms
71,152 KB
testcase_04 AC 70 ms
71,532 KB
testcase_05 AC 68 ms
71,372 KB
testcase_06 AC 67 ms
71,412 KB
testcase_07 AC 64 ms
71,620 KB
testcase_08 AC 66 ms
71,152 KB
testcase_09 AC 70 ms
71,124 KB
testcase_10 AC 69 ms
71,392 KB
testcase_11 AC 66 ms
71,388 KB
testcase_12 AC 76 ms
76,100 KB
testcase_13 AC 85 ms
76,448 KB
testcase_14 AC 85 ms
76,708 KB
testcase_15 AC 84 ms
75,580 KB
testcase_16 AC 80 ms
75,916 KB
testcase_17 AC 84 ms
76,180 KB
testcase_18 AC 79 ms
75,764 KB
testcase_19 AC 81 ms
75,888 KB
testcase_20 AC 89 ms
76,756 KB
testcase_21 AC 81 ms
75,912 KB
testcase_22 AC 91 ms
76,660 KB
testcase_23 AC 91 ms
76,544 KB
testcase_24 AC 95 ms
76,404 KB
testcase_25 AC 91 ms
76,676 KB
testcase_26 AC 91 ms
76,408 KB
testcase_27 AC 205 ms
107,088 KB
testcase_28 AC 205 ms
106,936 KB
testcase_29 AC 220 ms
107,896 KB
testcase_30 AC 218 ms
107,652 KB
testcase_31 AC 216 ms
107,364 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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())) + [10**10]

uf = UnionFind(N)
r1 = 0
r2 = 0
ans = [0] * N

for i in range(N):
    while X[r2] - X[i] <= B and r2 < N:
        r2 += 1
    while X[r1] - X[i] < A and r1 < N:
        r1 += 1
    for j in range(r1,r2):
        uf.union(i,j)

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

0