結果

問題 No.1170 Never Want to Walk
ユーザー stngstng
提出日時 2022-09-18 17:28:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,524 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 100,152 KB
最終ジャッジ日時 2023-08-23 18:13:55
合計ジャッジ時間 9,356 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,240 KB
testcase_01 AC 66 ms
71,168 KB
testcase_02 AC 69 ms
71,232 KB
testcase_03 AC 67 ms
71,324 KB
testcase_04 AC 66 ms
71,264 KB
testcase_05 AC 67 ms
71,244 KB
testcase_06 AC 67 ms
71,252 KB
testcase_07 AC 70 ms
71,360 KB
testcase_08 AC 68 ms
71,280 KB
testcase_09 AC 69 ms
71,140 KB
testcase_10 AC 69 ms
71,360 KB
testcase_11 AC 68 ms
71,200 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 102 ms
77,248 KB
testcase_23 AC 109 ms
77,588 KB
testcase_24 AC 110 ms
77,608 KB
testcase_25 AC 107 ms
77,464 KB
testcase_26 AC 111 ms
77,504 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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)
idx = [0]*n

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")
    ix = ia
    for j in range(ib-ia):
        if ix >= ib:
            break
        if not ki.same_check(i,ix):
            ki.union(i,ix)
            idx[ki.find(i)] = max(ix,idx[ki.find(i)])
            ix += 1
        else:
            ix = idx[ki.find(i)]
            #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