結果

問題 No.1170 Never Want to Walk
ユーザー rei60rei60
提出日時 2020-08-22 11:56:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,688 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 37,476 KB
最終ジャッジ日時 2024-04-23 07:09:13
合計ジャッジ時間 15,957 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
16,384 KB
testcase_01 AC 32 ms
11,008 KB
testcase_02 AC 34 ms
11,008 KB
testcase_03 AC 32 ms
11,008 KB
testcase_04 AC 35 ms
11,008 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 32 ms
10,880 KB
testcase_09 AC 32 ms
11,008 KB
testcase_10 AC 31 ms
11,008 KB
testcase_11 AC 31 ms
11,008 KB
testcase_12 AC 35 ms
11,008 KB
testcase_13 AC 36 ms
11,008 KB
testcase_14 AC 36 ms
11,008 KB
testcase_15 AC 35 ms
11,008 KB
testcase_16 AC 36 ms
11,136 KB
testcase_17 AC 38 ms
11,008 KB
testcase_18 AC 36 ms
11,136 KB
testcase_19 AC 36 ms
11,008 KB
testcase_20 AC 40 ms
11,136 KB
testcase_21 AC 35 ms
11,008 KB
testcase_22 AC 498 ms
11,136 KB
testcase_23 AC 169 ms
11,136 KB
testcase_24 AC 512 ms
11,136 KB
testcase_25 AC 499 ms
11,136 KB
testcase_26 AC 331 ms
11,008 KB
testcase_27 AC 1,591 ms
32,076 KB
testcase_28 AC 1,651 ms
31,900 KB
testcase_29 AC 1,403 ms
32,656 KB
testcase_30 AC 1,623 ms
32,432 KB
testcase_31 AC 1,516 ms
31,836 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 22 11:41:03 2020

"""

from bisect import bisect_left, bisect_right

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

uf = UnionFind(N)

for idx, i in enumerate(X):
    L_left = bisect_left(X, i-B)
    L_right = bisect_right(X, i-A)
    R_left = bisect_left(X, i+A)
    R_right = bisect_right(X, i+B)
    
    for j in range(L_left, L_right):
        uf.union(idx,j)
    for j in range(R_left, R_right):
        uf.union(idx,j)

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

0