結果

問題 No.1170 Never Want to Walk
ユーザー gr1msl3ygr1msl3y
提出日時 2022-05-18 21:18:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 660 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 105,184 KB
最終ジャッジ日時 2023-10-17 02:17:37
合計ジャッジ時間 12,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,652 KB
testcase_01 AC 40 ms
55,652 KB
testcase_02 AC 40 ms
55,652 KB
testcase_03 AC 40 ms
55,652 KB
testcase_04 AC 40 ms
55,652 KB
testcase_05 AC 40 ms
55,652 KB
testcase_06 AC 41 ms
55,652 KB
testcase_07 AC 40 ms
55,652 KB
testcase_08 AC 40 ms
55,652 KB
testcase_09 AC 40 ms
55,652 KB
testcase_10 AC 40 ms
55,652 KB
testcase_11 AC 41 ms
55,652 KB
testcase_12 AC 63 ms
72,104 KB
testcase_13 AC 71 ms
75,568 KB
testcase_14 AC 71 ms
75,568 KB
testcase_15 AC 63 ms
72,104 KB
testcase_16 AC 65 ms
72,516 KB
testcase_17 AC 73 ms
75,628 KB
testcase_18 AC 62 ms
72,104 KB
testcase_19 AC 65 ms
72,776 KB
testcase_20 AC 71 ms
75,508 KB
testcase_21 AC 63 ms
72,104 KB
testcase_22 AC 72 ms
75,628 KB
testcase_23 AC 73 ms
75,628 KB
testcase_24 AC 66 ms
73,272 KB
testcase_25 AC 72 ms
75,556 KB
testcase_26 AC 73 ms
75,628 KB
testcase_27 AC 541 ms
104,996 KB
testcase_28 AC 518 ms
104,924 KB
testcase_29 AC 660 ms
105,184 KB
testcase_30 AC 542 ms
105,052 KB
testcase_31 AC 563 ms
104,976 KB
testcase_32 AC 432 ms
104,828 KB
testcase_33 AC 464 ms
104,820 KB
testcase_34 AC 430 ms
104,988 KB
testcase_35 AC 443 ms
104,848 KB
testcase_36 AC 414 ms
104,812 KB
testcase_37 AC 432 ms
104,856 KB
testcase_38 AC 419 ms
104,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from bisect import bisect_left
N, A, B = map(int, input().split())
X = list(map(int, input().split()))


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.find(self.parents[x])

    def size(self, x):
        return -self.parents[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def root(self):
        return [i for i in range(self.n) if self.parents[i] < 0]

    def allgroup_members(self):
        members = defaultdict(set)
        for m in range(self.n):
            members[self.find(m)].add(m)
        return members


Y = [0]*N
uf = UnionFind(N)


def calc(l, r):
    resl = bisect_left(X, l)
    resr = bisect_left(X, r+1)
    return resl, resr


for i in range(N):
    x = X[i]
    l = calc(x-B, x-A)
    if l[1] > l[0]:
        uf.union(i, l[0])
        Y[l[0]] += 1
        Y[l[1]-1] -= 1
    r = calc(x+A, x+B)
    if r[0] < r[1]:
        uf.union(i, r[0])
        Y[r[0]] += 1
        Y[r[1]-1] -= 1

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

ans = [uf.size(i) for i in range(N)]
print(*ans, sep='\n')
0