結果

問題 No.1170 Never Want to Walk
ユーザー aqua_tenhouaqua_tenhou
提出日時 2020-08-14 22:08:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,717 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 37,568 KB
最終ジャッジ日時 2024-04-18 21:57:56
合計ジャッジ時間 13,319 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
16,640 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 29 ms
11,008 KB
testcase_04 AC 30 ms
11,008 KB
testcase_05 AC 34 ms
11,136 KB
testcase_06 AC 31 ms
11,008 KB
testcase_07 AC 30 ms
11,136 KB
testcase_08 AC 29 ms
11,136 KB
testcase_09 AC 29 ms
11,008 KB
testcase_10 AC 30 ms
11,008 KB
testcase_11 AC 30 ms
11,136 KB
testcase_12 AC 32 ms
11,136 KB
testcase_13 AC 33 ms
11,136 KB
testcase_14 AC 33 ms
11,008 KB
testcase_15 AC 32 ms
11,136 KB
testcase_16 AC 33 ms
11,008 KB
testcase_17 AC 35 ms
11,008 KB
testcase_18 AC 32 ms
11,136 KB
testcase_19 AC 34 ms
11,136 KB
testcase_20 AC 34 ms
11,008 KB
testcase_21 AC 32 ms
11,136 KB
testcase_22 AC 37 ms
11,008 KB
testcase_23 AC 36 ms
11,008 KB
testcase_24 AC 42 ms
11,008 KB
testcase_25 AC 39 ms
11,008 KB
testcase_26 AC 38 ms
11,008 KB
testcase_27 AC 1,604 ms
32,076 KB
testcase_28 AC 1,609 ms
31,784 KB
testcase_29 AC 1,364 ms
32,536 KB
testcase_30 AC 1,519 ms
32,352 KB
testcase_31 AC 1,471 ms
31,848 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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 and j < 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