結果

問題 No.1170 Never Want to Walk
ユーザー chineristACchineristAC
提出日時 2020-08-14 21:52:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 105,584 KB
最終ジャッジ日時 2024-04-18 21:37:17
合計ジャッジ時間 7,756 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,480 KB
testcase_01 AC 38 ms
52,224 KB
testcase_02 AC 41 ms
52,480 KB
testcase_03 AC 40 ms
52,480 KB
testcase_04 AC 37 ms
52,224 KB
testcase_05 AC 39 ms
52,736 KB
testcase_06 AC 38 ms
52,480 KB
testcase_07 AC 38 ms
52,736 KB
testcase_08 AC 35 ms
52,224 KB
testcase_09 AC 36 ms
52,736 KB
testcase_10 AC 36 ms
52,224 KB
testcase_11 AC 40 ms
52,864 KB
testcase_12 AC 68 ms
66,688 KB
testcase_13 AC 67 ms
68,864 KB
testcase_14 AC 68 ms
68,864 KB
testcase_15 AC 65 ms
67,584 KB
testcase_16 AC 70 ms
68,096 KB
testcase_17 AC 70 ms
68,608 KB
testcase_18 AC 65 ms
67,072 KB
testcase_19 AC 63 ms
68,096 KB
testcase_20 AC 71 ms
69,376 KB
testcase_21 AC 66 ms
67,072 KB
testcase_22 AC 71 ms
69,632 KB
testcase_23 AC 78 ms
70,528 KB
testcase_24 AC 73 ms
68,864 KB
testcase_25 AC 69 ms
68,864 KB
testcase_26 AC 68 ms
70,272 KB
testcase_27 AC 362 ms
104,652 KB
testcase_28 AC 358 ms
104,960 KB
testcase_29 AC 373 ms
105,584 KB
testcase_30 AC 393 ms
104,900 KB
testcase_31 AC 355 ms
104,832 KB
testcase_32 AC 347 ms
105,036 KB
testcase_33 AC 347 ms
104,956 KB
testcase_34 AC 358 ms
105,208 KB
testcase_35 AC 331 ms
105,196 KB
testcase_36 AC 307 ms
104,676 KB
testcase_37 AC 310 ms
104,820 KB
testcase_38 AC 354 ms
105,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def calc_group_num(self):
        N = len(self._parent)
        ans = 0
        for i in range(N):
            if self.find_root(i) == i:
                ans += 1
        return ans


import bisect

N,A,B=map(int,input().split())
x=list(map(int,input().split()))

uf=UnionFindVerSize(N)
data=[0]*N
for i in range(N):
    idL=bisect.bisect_left(x,x[i]+A)
    idR=bisect.bisect_right(x,x[i]+B)-1
    if idL<=idR:
        uf.unite(i,idL)
        data[idL]+=1
        data[idR]-=1


for i in range(1,N):
    data[i]+=data[i-1]
for i in range(N-1):
    if data[i]:
        uf.unite(i,i+1)

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