結果

問題 No.1170 Never Want to Walk
ユーザー uni_pythonuni_python
提出日時 2020-08-15 11:54:32
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 2,985 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 106,968 KB
最終ジャッジ日時 2023-08-01 01:06:51
合計ジャッジ時間 9,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,396 KB
testcase_01 AC 70 ms
71,144 KB
testcase_02 AC 70 ms
71,396 KB
testcase_03 AC 69 ms
71,368 KB
testcase_04 WA -
testcase_05 AC 70 ms
71,428 KB
testcase_06 AC 69 ms
71,340 KB
testcase_07 AC 71 ms
71,472 KB
testcase_08 AC 69 ms
71,284 KB
testcase_09 AC 69 ms
71,468 KB
testcase_10 AC 69 ms
71,440 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 89 ms
76,512 KB
testcase_23 AC 100 ms
77,416 KB
testcase_24 AC 83 ms
76,444 KB
testcase_25 AC 89 ms
76,520 KB
testcase_26 AC 96 ms
76,104 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 196 ms
103,468 KB
testcase_33 AC 222 ms
104,068 KB
testcase_34 AC 452 ms
106,968 KB
testcase_35 AC 213 ms
104,312 KB
testcase_36 AC 251 ms
104,408 KB
testcase_37 AC 734 ms
104,240 KB
testcase_38 AC 257 ms
106,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    ################
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意),根の場合は"-(要素数)"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        重いかも!  members(x):要素xが属するグループに属する要素をリストで返す
        roots:全ての根の要素を返す
        group_count():グループの数を返す
        重いかも! all_group_members():{根要素:[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            #根を探す&つなぎかえる
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

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

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

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

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

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

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    ################


    import bisect
    
    mod=10**9+7
    N,A,B=MI()
    x=LI()
    uf=UnionFind(N)
    
    L=[0]*N#他から繋がられたか,繋がれたところからはスタートしなくて良い
    for i in range(N):
        if L[i]==0:
            
            #進行方向
            nl=bisect.bisect_left(x,x[i]+A)
            nr=bisect.bisect_right(x,x[i]+B)
            for j in range(nl,nr):
                uf.union(i,j)
                L[j]=1
                
            #逆向き
            nl=bisect.bisect_left(x,x[i]-B)
            nr=bisect.bisect_right(x,x[i]-A)
            for j in range(nl,nr):
                uf.union(i,j)
    
    for i in range(N):
        print(uf.size(i))
            
            
            
    

    
    


main()
0