結果

問題 No.1170 Never Want to Walk
ユーザー chineristACchineristAC
提出日時 2020-08-14 21:52:50
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 106,748 KB
最終ジャッジ日時 2023-07-31 22:04:11
合計ジャッジ時間 10,055 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,312 KB
testcase_01 AC 71 ms
71,568 KB
testcase_02 AC 71 ms
71,196 KB
testcase_03 AC 71 ms
71,484 KB
testcase_04 AC 70 ms
71,164 KB
testcase_05 AC 70 ms
71,364 KB
testcase_06 AC 69 ms
71,308 KB
testcase_07 AC 71 ms
71,428 KB
testcase_08 AC 72 ms
71,348 KB
testcase_09 AC 70 ms
71,568 KB
testcase_10 AC 72 ms
71,504 KB
testcase_11 AC 72 ms
71,044 KB
testcase_12 AC 91 ms
75,948 KB
testcase_13 AC 92 ms
76,168 KB
testcase_14 AC 92 ms
76,244 KB
testcase_15 AC 91 ms
76,040 KB
testcase_16 AC 94 ms
76,152 KB
testcase_17 AC 95 ms
76,100 KB
testcase_18 AC 93 ms
76,176 KB
testcase_19 AC 95 ms
75,900 KB
testcase_20 AC 95 ms
76,108 KB
testcase_21 AC 91 ms
76,036 KB
testcase_22 AC 93 ms
75,768 KB
testcase_23 AC 95 ms
76,232 KB
testcase_24 AC 92 ms
76,044 KB
testcase_25 AC 92 ms
75,952 KB
testcase_26 AC 99 ms
76,112 KB
testcase_27 AC 401 ms
105,968 KB
testcase_28 AC 401 ms
105,480 KB
testcase_29 AC 425 ms
105,940 KB
testcase_30 AC 408 ms
106,220 KB
testcase_31 AC 402 ms
105,184 KB
testcase_32 AC 406 ms
105,648 KB
testcase_33 AC 422 ms
105,804 KB
testcase_34 AC 397 ms
105,916 KB
testcase_35 AC 383 ms
106,748 KB
testcase_36 AC 372 ms
106,688 KB
testcase_37 AC 361 ms
105,600 KB
testcase_38 AC 403 ms
105,720 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