結果

問題 No.1170 Never Want to Walk
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-08-14 22:52:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,544 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 128,808 KB
最終ジャッジ日時 2024-04-18 22:41:08
合計ジャッジ時間 6,956 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,352 KB
testcase_01 AC 44 ms
52,096 KB
testcase_02 AC 42 ms
52,224 KB
testcase_03 AC 44 ms
52,224 KB
testcase_04 AC 45 ms
51,968 KB
testcase_05 AC 42 ms
52,096 KB
testcase_06 AC 42 ms
52,352 KB
testcase_07 AC 44 ms
52,224 KB
testcase_08 AC 44 ms
52,480 KB
testcase_09 AC 39 ms
52,096 KB
testcase_10 AC 41 ms
51,968 KB
testcase_11 AC 42 ms
52,352 KB
testcase_12 AC 62 ms
64,000 KB
testcase_13 AC 68 ms
66,048 KB
testcase_14 AC 71 ms
66,432 KB
testcase_15 AC 66 ms
63,744 KB
testcase_16 AC 63 ms
65,024 KB
testcase_17 AC 67 ms
67,456 KB
testcase_18 AC 57 ms
64,000 KB
testcase_19 AC 64 ms
65,536 KB
testcase_20 AC 72 ms
67,200 KB
testcase_21 AC 60 ms
64,128 KB
testcase_22 AC 64 ms
67,328 KB
testcase_23 AC 74 ms
68,224 KB
testcase_24 AC 69 ms
67,072 KB
testcase_25 AC 67 ms
67,712 KB
testcase_26 AC 66 ms
66,816 KB
testcase_27 AC 293 ms
126,904 KB
testcase_28 AC 315 ms
108,920 KB
testcase_29 AC 324 ms
127,448 KB
testcase_30 AC 291 ms
127,820 KB
testcase_31 AC 310 ms
126,124 KB
testcase_32 AC 262 ms
128,296 KB
testcase_33 AC 263 ms
126,588 KB
testcase_34 AC 277 ms
128,808 KB
testcase_35 AC 286 ms
127,576 KB
testcase_36 AC 279 ms
126,560 KB
testcase_37 AC 312 ms
126,712 KB
testcase_38 AC 282 ms
127,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                n_root, child = root, unite_root
            else:
                n_root, child = unite_root, root
            child.parent_ = n_root
            n_root.rank_ = max(n_root.rank_, child.rank_ + 1)
            n_root.member_num_ = n_root.member_num_ + child.member_num_


N, A, B = map(int, input().split())
X = list(map(int, input().split()))
X.append(10**19)
nodes = [UnionFindNode(i) for i in range(N)]
j=k=-1
for i in range(N):
    while X[j+1] < X[i]+A:
        j+=1
    ks = []
    while X[k+1] <= X[i]+B:
        k+=1
        if j < k:
            ks.append(k)
    if j < k:
        nodes[i].unite(nodes[j+1])
    for kk in ks:
        nodes[i].unite(nodes[kk])
for i in range(N):
    print(nodes[i].root().member_num_)
0