結果

問題 No.1170 Never Want to Walk
ユーザー tamatotamato
提出日時 2020-08-14 21:48:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 1,669 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 82,676 KB
実行使用メモリ 105,740 KB
最終ジャッジ日時 2024-04-18 21:30:44
合計ジャッジ時間 9,461 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,736 KB
testcase_01 AC 38 ms
52,992 KB
testcase_02 AC 38 ms
53,248 KB
testcase_03 AC 37 ms
52,864 KB
testcase_04 AC 36 ms
52,736 KB
testcase_05 AC 38 ms
52,480 KB
testcase_06 AC 37 ms
52,608 KB
testcase_07 AC 38 ms
52,480 KB
testcase_08 AC 39 ms
52,864 KB
testcase_09 AC 39 ms
52,736 KB
testcase_10 AC 39 ms
52,992 KB
testcase_11 AC 37 ms
53,120 KB
testcase_12 AC 52 ms
66,176 KB
testcase_13 AC 57 ms
69,376 KB
testcase_14 AC 58 ms
69,888 KB
testcase_15 AC 55 ms
66,488 KB
testcase_16 AC 57 ms
67,072 KB
testcase_17 AC 62 ms
71,168 KB
testcase_18 AC 56 ms
66,304 KB
testcase_19 AC 57 ms
67,840 KB
testcase_20 AC 59 ms
70,272 KB
testcase_21 AC 54 ms
66,944 KB
testcase_22 AC 61 ms
72,960 KB
testcase_23 AC 61 ms
72,448 KB
testcase_24 AC 60 ms
72,448 KB
testcase_25 AC 61 ms
71,552 KB
testcase_26 AC 62 ms
72,828 KB
testcase_27 AC 516 ms
105,444 KB
testcase_28 AC 504 ms
105,232 KB
testcase_29 AC 556 ms
105,740 KB
testcase_30 AC 515 ms
105,500 KB
testcase_31 AC 525 ms
104,928 KB
testcase_32 AC 446 ms
105,272 KB
testcase_33 AC 592 ms
104,936 KB
testcase_34 AC 459 ms
105,616 KB
testcase_35 AC 468 ms
105,548 KB
testcase_36 AC 419 ms
105,100 KB
testcase_37 AC 459 ms
105,000 KB
testcase_38 AC 488 ms
105,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            while self.root[x] >= 0:
                x = self.root[x]
            return x

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

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

        def size(self, x):
            return -self.root[self.find_root(x)]

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

    UF = UnionFind(N)
    imos = [0] * (N+1)
    for i in range(N):
        x = X[i]
        j0 = bisect_left(X, x+A)
        j1 = bisect_left(X, x+B+1) - 1
        if i < j0 <= j1 < N:
            UF.unite(i + 1, j0 + 1)
            UF.unite(i+1, j1+1)
        if j0+1 < j1:
            imos[j0+1] += 1
            imos[j1] -= 1

    val = 0
    for i in range(N):
        val += imos[i]
        if val > 0:
            UF.unite(i, i+1)
            UF.unite(i+1, i+2)
    for i in range(1, N+1):
        print(UF.size(i))


if __name__ == '__main__':
    main()
0