結果

問題 No.1170 Never Want to Walk
ユーザー KuonAyanoKuonAyano
提出日時 2020-08-14 22:11:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,480 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 107,392 KB
最終ジャッジ日時 2024-04-18 22:01:31
合計ジャッジ時間 7,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
57,984 KB
testcase_01 AC 38 ms
52,864 KB
testcase_02 AC 37 ms
52,480 KB
testcase_03 AC 35 ms
52,480 KB
testcase_04 AC 37 ms
52,864 KB
testcase_05 AC 40 ms
52,992 KB
testcase_06 AC 37 ms
52,224 KB
testcase_07 AC 36 ms
52,992 KB
testcase_08 AC 36 ms
52,608 KB
testcase_09 AC 37 ms
52,480 KB
testcase_10 AC 33 ms
53,120 KB
testcase_11 AC 34 ms
52,736 KB
testcase_12 AC 55 ms
67,584 KB
testcase_13 AC 66 ms
72,192 KB
testcase_14 AC 63 ms
70,864 KB
testcase_15 AC 59 ms
67,456 KB
testcase_16 AC 59 ms
68,096 KB
testcase_17 AC 67 ms
74,392 KB
testcase_18 AC 58 ms
66,944 KB
testcase_19 AC 60 ms
68,736 KB
testcase_20 AC 70 ms
74,368 KB
testcase_21 AC 57 ms
67,072 KB
testcase_22 AC 68 ms
71,808 KB
testcase_23 AC 76 ms
76,032 KB
testcase_24 AC 70 ms
72,448 KB
testcase_25 AC 65 ms
70,656 KB
testcase_26 AC 78 ms
74,388 KB
testcase_27 AC 292 ms
101,440 KB
testcase_28 AC 292 ms
101,504 KB
testcase_29 AC 288 ms
102,016 KB
testcase_30 AC 281 ms
101,632 KB
testcase_31 AC 295 ms
101,236 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

uf = UnionFind(N)

import bisect as bi

for i in range (0, N-1):
	right = bi.bisect_right(L, L[i]+B)
	left = bi.bisect_left(L, L[i]+A)
	if right - left > 0:
		for j in range(left, right):
			uf.union(i, j)
            
for i in range (0, N):
	print(uf.size(i))
0