結果

問題 No.1170 Never Want to Walk
ユーザー stngstng
提出日時 2022-09-18 16:56:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,344 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 104,144 KB
最終ジャッジ日時 2023-08-23 18:12:50
合計ジャッジ時間 9,909 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,552 KB
testcase_01 AC 75 ms
71,276 KB
testcase_02 AC 74 ms
70,964 KB
testcase_03 AC 76 ms
71,244 KB
testcase_04 AC 73 ms
70,848 KB
testcase_05 AC 75 ms
71,088 KB
testcase_06 AC 76 ms
71,112 KB
testcase_07 AC 77 ms
70,976 KB
testcase_08 AC 76 ms
71,084 KB
testcase_09 AC 76 ms
70,960 KB
testcase_10 AC 76 ms
71,056 KB
testcase_11 AC 76 ms
70,992 KB
testcase_12 AC 97 ms
75,892 KB
testcase_13 AC 105 ms
77,120 KB
testcase_14 AC 106 ms
77,016 KB
testcase_15 AC 99 ms
75,968 KB
testcase_16 AC 99 ms
75,964 KB
testcase_17 AC 109 ms
77,412 KB
testcase_18 AC 95 ms
75,816 KB
testcase_19 AC 100 ms
75,872 KB
testcase_20 AC 114 ms
77,140 KB
testcase_21 AC 96 ms
75,864 KB
testcase_22 AC 110 ms
77,496 KB
testcase_23 AC 113 ms
76,968 KB
testcase_24 AC 119 ms
77,728 KB
testcase_25 AC 108 ms
76,992 KB
testcase_26 AC 116 ms
77,248 KB
testcase_27 AC 351 ms
99,872 KB
testcase_28 AC 337 ms
99,352 KB
testcase_29 AC 359 ms
99,344 KB
testcase_30 AC 359 ms
99,708 KB
testcase_31 AC 354 ms
99,476 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,a,b = map(int,input().split())
x = [int(i) for i in input().split()]

ki = UnionFind(n+1)

for i in range(n):
    ia = bisect.bisect_left(x,x[i]+a)
    ib = bisect.bisect_right(x,x[i]+b)
    #print(i,ia,"srt")
    for j in range(ib-ia):
        if not ki.same_check(i,ia+j):
            ki.union(i,ia+j)
            #print(i,ia+j)
#ki.union(1,5)
li = [0]*n
num = [0]*n

for i in range(n):
    tmp = ki.find(i)
    li[i] = tmp
    num[tmp] += 1
    #print(ki.find(i),"find")

for i in range(n):
    print(num[li[i]])
0