結果

問題 No.1170 Never Want to Walk
ユーザー ntudantuda
提出日時 2021-10-02 00:21:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,532 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 108,392 KB
最終ジャッジ日時 2023-09-27 00:36:55
合計ジャッジ時間 7,705 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,104 KB
testcase_01 AC 71 ms
71,208 KB
testcase_02 AC 70 ms
71,204 KB
testcase_03 AC 69 ms
71,480 KB
testcase_04 AC 71 ms
71,252 KB
testcase_05 AC 70 ms
71,232 KB
testcase_06 AC 69 ms
71,156 KB
testcase_07 AC 68 ms
71,208 KB
testcase_08 AC 70 ms
71,204 KB
testcase_09 AC 66 ms
71,048 KB
testcase_10 AC 69 ms
71,244 KB
testcase_11 AC 70 ms
71,416 KB
testcase_12 AC 84 ms
76,652 KB
testcase_13 AC 87 ms
76,772 KB
testcase_14 AC 91 ms
76,320 KB
testcase_15 AC 83 ms
76,008 KB
testcase_16 AC 84 ms
76,496 KB
testcase_17 AC 86 ms
76,276 KB
testcase_18 AC 83 ms
76,400 KB
testcase_19 AC 86 ms
76,472 KB
testcase_20 AC 87 ms
76,188 KB
testcase_21 AC 85 ms
76,524 KB
testcase_22 AC 89 ms
76,604 KB
testcase_23 AC 93 ms
76,552 KB
testcase_24 AC 84 ms
76,748 KB
testcase_25 AC 85 ms
76,572 KB
testcase_26 AC 92 ms
76,524 KB
testcase_27 AC 214 ms
107,284 KB
testcase_28 AC 220 ms
106,956 KB
testcase_29 AC 226 ms
107,924 KB
testcase_30 AC 229 ms
107,772 KB
testcase_31 AC 222 ms
106,992 KB
testcase_32 AC 186 ms
108,296 KB
testcase_33 AC 180 ms
107,880 KB
testcase_34 AC 195 ms
107,060 KB
testcase_35 AC 177 ms
108,392 KB
testcase_36 AC 182 ms
106,604 KB
testcase_37 AC 182 ms
106,664 KB
testcase_38 AC 180 ms
107,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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())) + [10**10]

uf = UnionFind(N)
l = 0
r = 0
ans = [0] * N
for i in range(N):
    x = X[i]
    while X[r] - x <= B:
        r += 1
    while X[l] - x < A:
        l += 1
    for j in range(l,r):
        uf.union(i,j)
    l = max(0,r-2)
ans = [0] * N
for i in range(N):
    ans[i] = uf.size(i)
for a in ans:
    print(a)
0