結果

問題 No.1170 Never Want to Walk
ユーザー tktk_snsntktk_snsn
提出日時 2020-08-14 21:38:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,199 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 82,296 KB
実行使用メモリ 109,300 KB
最終ジャッジ日時 2024-04-18 21:13:33
合計ジャッジ時間 8,156 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
57,856 KB
testcase_01 AC 43 ms
52,608 KB
testcase_02 AC 42 ms
52,736 KB
testcase_03 AC 43 ms
52,224 KB
testcase_04 AC 42 ms
52,224 KB
testcase_05 AC 42 ms
52,352 KB
testcase_06 AC 42 ms
52,480 KB
testcase_07 AC 43 ms
52,480 KB
testcase_08 AC 44 ms
52,096 KB
testcase_09 AC 43 ms
52,352 KB
testcase_10 AC 43 ms
52,096 KB
testcase_11 AC 42 ms
52,224 KB
testcase_12 AC 63 ms
63,872 KB
testcase_13 AC 75 ms
69,888 KB
testcase_14 AC 72 ms
67,840 KB
testcase_15 AC 65 ms
64,768 KB
testcase_16 AC 66 ms
65,408 KB
testcase_17 AC 80 ms
70,400 KB
testcase_18 AC 64 ms
64,512 KB
testcase_19 AC 66 ms
65,408 KB
testcase_20 AC 78 ms
70,272 KB
testcase_21 AC 64 ms
64,512 KB
testcase_22 AC 75 ms
68,736 KB
testcase_23 AC 81 ms
71,040 KB
testcase_24 AC 85 ms
70,272 KB
testcase_25 AC 75 ms
67,840 KB
testcase_26 AC 82 ms
71,040 KB
testcase_27 AC 271 ms
107,044 KB
testcase_28 AC 252 ms
106,760 KB
testcase_29 AC 316 ms
107,772 KB
testcase_30 AC 270 ms
106,940 KB
testcase_31 AC 292 ms
106,992 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数
        self.rank = [0] * (n + 1)

    def find(self, x):  # xの根となる要素番号を返す
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        return -self.root[self.find(x)]


N, A, B = map(int, input().split())
X = tuple(map(int, input().split()))
uf = UF_tree(N)
for i, x in enumerate(X):
    L = bisect.bisect_left(X, x + A)
    while L < N and X[L] <= x + B:
        uf.unite(i, L)
        L += 1

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