結果

問題 No.1170 Never Want to Walk
ユーザー stngstng
提出日時 2022-09-18 16:55:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,337 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 85,264 KB
実行使用メモリ 104,920 KB
最終ジャッジ日時 2023-08-23 18:12:39
合計ジャッジ時間 10,989 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
75,556 KB
testcase_01 AC 68 ms
71,204 KB
testcase_02 AC 67 ms
71,264 KB
testcase_03 AC 70 ms
71,336 KB
testcase_04 AC 67 ms
71,184 KB
testcase_05 AC 67 ms
71,288 KB
testcase_06 AC 69 ms
71,176 KB
testcase_07 AC 70 ms
71,208 KB
testcase_08 AC 83 ms
71,360 KB
testcase_09 AC 66 ms
71,176 KB
testcase_10 AC 66 ms
71,108 KB
testcase_11 AC 67 ms
71,072 KB
testcase_12 AC 86 ms
75,864 KB
testcase_13 AC 96 ms
76,948 KB
testcase_14 AC 98 ms
76,976 KB
testcase_15 AC 91 ms
75,976 KB
testcase_16 AC 91 ms
75,684 KB
testcase_17 AC 98 ms
77,352 KB
testcase_18 AC 88 ms
75,760 KB
testcase_19 AC 90 ms
75,760 KB
testcase_20 AC 102 ms
77,324 KB
testcase_21 AC 86 ms
75,720 KB
testcase_22 AC 101 ms
77,316 KB
testcase_23 AC 106 ms
77,328 KB
testcase_24 AC 107 ms
77,444 KB
testcase_25 AC 96 ms
77,280 KB
testcase_26 AC 103 ms
77,248 KB
testcase_27 AC 321 ms
99,528 KB
testcase_28 AC 303 ms
99,080 KB
testcase_29 AC 335 ms
99,244 KB
testcase_30 AC 335 ms
99,616 KB
testcase_31 AC 318 ms
99,552 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):
    li[i] = ki.find(i)
    num[ki.find(i)] += 1
    #print(ki.find(i),"find")

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