結果

問題 No.1170 Never Want to Walk
ユーザー 👑 KazunKazun
提出日時 2020-08-14 21:29:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,084 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 107,136 KB
最終ジャッジ日時 2024-04-18 20:43:44
合計ジャッジ時間 6,687 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
57,472 KB
testcase_01 AC 40 ms
52,096 KB
testcase_02 AC 38 ms
52,352 KB
testcase_03 AC 38 ms
52,480 KB
testcase_04 AC 43 ms
51,968 KB
testcase_05 AC 41 ms
51,968 KB
testcase_06 AC 38 ms
52,480 KB
testcase_07 AC 39 ms
52,352 KB
testcase_08 AC 39 ms
52,224 KB
testcase_09 AC 36 ms
51,968 KB
testcase_10 AC 38 ms
52,096 KB
testcase_11 AC 36 ms
52,608 KB
testcase_12 AC 81 ms
70,528 KB
testcase_13 AC 97 ms
75,648 KB
testcase_14 AC 88 ms
76,416 KB
testcase_15 AC 78 ms
70,656 KB
testcase_16 AC 83 ms
71,424 KB
testcase_17 AC 92 ms
75,904 KB
testcase_18 AC 73 ms
70,144 KB
testcase_19 AC 99 ms
75,392 KB
testcase_20 AC 105 ms
76,032 KB
testcase_21 AC 79 ms
70,656 KB
testcase_22 AC 97 ms
75,264 KB
testcase_23 AC 93 ms
75,776 KB
testcase_24 AC 98 ms
75,392 KB
testcase_25 AC 106 ms
75,648 KB
testcase_26 AC 103 ms
76,032 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Union_Find():
    def __init__(self,N):
        """0,1,...,n-1を要素として初期化する.

        n:要素数
        """
        self.n=N
        self.parents=[-1]*N

    def find(self, x):
        """要素xの属している族を調べる.

        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,yを同一視する.

        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):
        """要素xの属している要素の数.
 
        x:要素
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """要素x,yは同一視されているか?

        x,y:要素
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """要素xが属している族の要素.

        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()))
U=Union_Find(N)

for i in range(N):
    for j in range(i+1,N):
        if A<=abs(X[i]-X[j])<=B:
            U.union(i,j)

Ans=[0]*N
for i in range(N):
    Ans[i]=len(U.members(i))

print("\n".join(map(str,Ans)))
0