結果

問題 No.1170 Never Want to Walk
ユーザー aqua_tenhouaqua_tenhou
提出日時 2020-08-14 22:12:00
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,707 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 103,160 KB
最終ジャッジ日時 2024-04-18 22:02:42
合計ジャッジ時間 7,833 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,736 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 37 ms
52,864 KB
testcase_06 AC 36 ms
52,864 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 72 ms
72,448 KB
testcase_14 AC 79 ms
76,072 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 75 ms
74,244 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#UnionFind
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())

import bisect

n,a,b = map(int,input().split())
x = list(map(int,input().split()))

uf = UnionFind(n+1)

for i in range(n):
    
    A = bisect.bisect_left(x,x[i]+a)
    B = bisect.bisect_left(x,x[i]+b)
    
    
    for j in range(A,B+1):
        if i == j:
            pass
        
        if A < n:
            if j != A and a <= abs(x[j]-x[A]) <= b:
                break
        
        
        if j >= n:
            break

        if a <= abs(x[i]-x[j]) <= b:
            uf.union(i,j)
            
for i in range(n):
    print(uf.size(i))
0