結果

問題 No.1170 Never Want to Walk
ユーザー terasaterasa
提出日時 2022-05-24 02:11:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,974 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 103,252 KB
最終ジャッジ日時 2023-10-20 17:52:09
合計ジャッジ時間 13,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,712 KB
testcase_01 AC 43 ms
55,712 KB
testcase_02 AC 43 ms
55,712 KB
testcase_03 AC 41 ms
55,712 KB
testcase_04 AC 40 ms
55,712 KB
testcase_05 AC 44 ms
55,712 KB
testcase_06 AC 40 ms
55,712 KB
testcase_07 AC 41 ms
55,712 KB
testcase_08 AC 41 ms
55,712 KB
testcase_09 AC 39 ms
55,712 KB
testcase_10 AC 39 ms
55,712 KB
testcase_11 AC 39 ms
55,712 KB
testcase_12 AC 76 ms
75,724 KB
testcase_13 AC 81 ms
76,236 KB
testcase_14 AC 82 ms
76,424 KB
testcase_15 AC 79 ms
75,656 KB
testcase_16 AC 76 ms
75,632 KB
testcase_17 AC 81 ms
76,432 KB
testcase_18 AC 75 ms
75,720 KB
testcase_19 AC 76 ms
75,720 KB
testcase_20 AC 84 ms
76,412 KB
testcase_21 AC 73 ms
75,648 KB
testcase_22 AC 376 ms
76,296 KB
testcase_23 AC 166 ms
76,260 KB
testcase_24 AC 460 ms
76,360 KB
testcase_25 AC 393 ms
76,300 KB
testcase_26 AC 272 ms
76,280 KB
testcase_27 AC 896 ms
101,264 KB
testcase_28 AC 1,065 ms
101,228 KB
testcase_29 AC 942 ms
103,252 KB
testcase_30 AC 997 ms
103,204 KB
testcase_31 AC 861 ms
101,220 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict, Counter
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


class UnionFind:
    def __init__(self, N):
        self.N = N
        self.par = [-1] * N

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if x > y:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

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

    def roots(self):
        return [i for i in range(self.N) if self.par[i] < 0]

    def members(self, x):
        p = self.find(x)
        return [i for i in range(self.N) if self.find(i) == p]


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


N, A, B = map(int, input().split())
X = list(map(int, input().split()))
uf = UnionFind(N)
for i, x in enumerate(X):
    a = index_ge(X, x - B)
    b = index_le(X, x - A)
    c = index_ge(X, x + A)
    d = index_le(X, x + B)

    for j in range(a, b + 1):
        uf.unite(i, j)
    for j in range(c, d + 1):
        uf.unite(i, j)
for i in range(N):
    print(uf.size(i))
0