結果

問題 No.1170 Never Want to Walk
ユーザー ntudantuda
提出日時 2021-10-01 23:40:43
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,522 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 107,832 KB
最終ジャッジ日時 2023-09-26 23:00:36
合計ジャッジ時間 9,955 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,308 KB
testcase_01 AC 69 ms
71,228 KB
testcase_02 AC 67 ms
71,264 KB
testcase_03 AC 66 ms
71,384 KB
testcase_04 AC 67 ms
71,368 KB
testcase_05 AC 68 ms
71,260 KB
testcase_06 AC 69 ms
71,236 KB
testcase_07 AC 69 ms
71,488 KB
testcase_08 AC 69 ms
71,232 KB
testcase_09 AC 72 ms
71,160 KB
testcase_10 AC 68 ms
71,160 KB
testcase_11 AC 69 ms
71,368 KB
testcase_12 AC 84 ms
75,860 KB
testcase_13 AC 90 ms
76,572 KB
testcase_14 AC 89 ms
76,480 KB
testcase_15 AC 78 ms
75,768 KB
testcase_16 AC 82 ms
75,864 KB
testcase_17 AC 87 ms
76,188 KB
testcase_18 AC 81 ms
75,860 KB
testcase_19 AC 81 ms
75,772 KB
testcase_20 AC 91 ms
76,592 KB
testcase_21 AC 79 ms
75,772 KB
testcase_22 AC 94 ms
76,584 KB
testcase_23 AC 94 ms
76,580 KB
testcase_24 AC 98 ms
76,412 KB
testcase_25 AC 93 ms
76,716 KB
testcase_26 AC 94 ms
76,336 KB
testcase_27 AC 222 ms
106,832 KB
testcase_28 AC 229 ms
107,440 KB
testcase_29 AC 223 ms
107,832 KB
testcase_30 AC 228 ms
107,232 KB
testcase_31 AC 226 ms
107,328 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
r1 = 0
r2 = 0
ans = [0] * N
for i in range(N):
    x = X[i]
    while X[r2] - x <= B:
        r2 += 1
    while X[r1] - x < A:
        r1 += 1
    for j in range(r1,r2):
        uf.union(i,j)
ans = [0] * N
for i in range(N):
    ans[i] = uf.size(i)
for a in ans:
    print(a)

0