結果

問題 No.1170 Never Want to Walk
ユーザー hahho28hahho28
提出日時 2021-02-28 02:06:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 107,536 KB
最終ジャッジ日時 2024-04-10 15:53:02
合計ジャッジ時間 7,419 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,272 KB
testcase_01 AC 35 ms
52,540 KB
testcase_02 AC 36 ms
52,408 KB
testcase_03 AC 37 ms
52,880 KB
testcase_04 AC 37 ms
54,044 KB
testcase_05 AC 36 ms
53,340 KB
testcase_06 AC 35 ms
51,996 KB
testcase_07 AC 35 ms
52,836 KB
testcase_08 AC 35 ms
53,372 KB
testcase_09 AC 35 ms
53,972 KB
testcase_10 AC 35 ms
52,892 KB
testcase_11 AC 34 ms
52,724 KB
testcase_12 AC 47 ms
63,172 KB
testcase_13 AC 49 ms
64,508 KB
testcase_14 AC 49 ms
65,536 KB
testcase_15 AC 51 ms
65,620 KB
testcase_16 AC 48 ms
64,036 KB
testcase_17 AC 48 ms
65,676 KB
testcase_18 AC 48 ms
63,044 KB
testcase_19 AC 48 ms
64,116 KB
testcase_20 AC 50 ms
65,388 KB
testcase_21 AC 47 ms
63,692 KB
testcase_22 AC 51 ms
67,128 KB
testcase_23 AC 51 ms
66,700 KB
testcase_24 AC 51 ms
66,504 KB
testcase_25 AC 52 ms
66,996 KB
testcase_26 AC 51 ms
67,636 KB
testcase_27 AC 267 ms
103,360 KB
testcase_28 AC 259 ms
107,352 KB
testcase_29 AC 281 ms
103,872 KB
testcase_30 AC 270 ms
103,360 KB
testcase_31 AC 255 ms
107,536 KB
testcase_32 AC 249 ms
103,548 KB
testcase_33 AC 240 ms
107,348 KB
testcase_34 AC 270 ms
102,632 KB
testcase_35 AC 238 ms
102,968 KB
testcase_36 AC 238 ms
103,248 KB
testcase_37 AC 233 ms
102,548 KB
testcase_38 AC 236 ms
102,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class DisjointSet:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0]*size
    
    def find(self, x):
        stack = []
        parent = self.parent
        while parent[x] != x:
            stack.append(x)
            x = parent[x]
        for y in stack:
            parent[y] = x
        return x

    def union(self, x, y):
        xr, yr = self.find(x), self.find(y)
        
        if self.rank[xr] > self.rank[yr]:
            self.parent[yr] = xr
        elif self.rank[xr] < self.rank[yr]:
            self.parent[xr] = yr
        elif xr != yr:
            self.parent[yr] = xr
            self.rank[xr] += 1

n,a,b = map(int,input().split())
X = list(map(int,input().split()))
ds = DisjointSet(n)

j = 0

for i,xi in enumerate(X):
    while j < n and X[j] < a+xi:
        j += 1
    if j == n:
        break
    if X[j] <= b+xi:
        ds.union(i,j)
    while j+1 < n and X[j+1] <= b+xi:
        ds.union(j,j+1)
        j += 1


cnt = [0]*n
for i in range(n):
    cnt[ds.find(i)] += 1

for i in range(n):
    print(cnt[ds.find(i)])


0