結果

問題 No.1170 Never Want to Walk
ユーザー titiatitia
提出日時 2020-08-14 22:44:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 82,000 KB
実行使用メモリ 109,920 KB
最終ジャッジ日時 2024-04-18 22:34:25
合計ジャッジ時間 9,048 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,736 KB
testcase_01 AC 39 ms
52,224 KB
testcase_02 AC 39 ms
52,608 KB
testcase_03 AC 41 ms
52,096 KB
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 41 ms
52,096 KB
testcase_06 AC 41 ms
52,352 KB
testcase_07 AC 41 ms
52,608 KB
testcase_08 AC 39 ms
52,224 KB
testcase_09 AC 39 ms
52,224 KB
testcase_10 AC 40 ms
52,224 KB
testcase_11 AC 41 ms
52,608 KB
testcase_12 AC 73 ms
68,864 KB
testcase_13 AC 74 ms
72,064 KB
testcase_14 AC 77 ms
72,960 KB
testcase_15 AC 70 ms
68,992 KB
testcase_16 AC 72 ms
70,528 KB
testcase_17 AC 73 ms
71,936 KB
testcase_18 AC 73 ms
68,224 KB
testcase_19 AC 69 ms
70,912 KB
testcase_20 AC 71 ms
72,448 KB
testcase_21 AC 66 ms
69,120 KB
testcase_22 AC 73 ms
72,064 KB
testcase_23 AC 76 ms
73,088 KB
testcase_24 AC 76 ms
72,704 KB
testcase_25 AC 73 ms
71,808 KB
testcase_26 AC 77 ms
73,344 KB
testcase_27 AC 438 ms
103,880 KB
testcase_28 AC 421 ms
104,352 KB
testcase_29 AC 445 ms
102,936 KB
testcase_30 AC 494 ms
104,508 KB
testcase_31 AC 451 ms
103,524 KB
testcase_32 AC 314 ms
108,108 KB
testcase_33 AC 408 ms
109,920 KB
testcase_34 AC 357 ms
107,360 KB
testcase_35 AC 414 ms
107,824 KB
testcase_36 AC 366 ms
109,068 KB
testcase_37 AC 319 ms
107,628 KB
testcase_38 AC 314 ms
109,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import bisect

N,a,b=map(int,input().split())
X=list(map(int,input().split()))

# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

s=t=-1
for i in range(N):
    s2=bisect.bisect_left(X,X[i]+a)
    t2=bisect.bisect_right(X,X[i]+b)

    if s2<t:
        Union(i,i-1)
        for j in range(t,t2):
            Union(i,j)

    else:
        for j in range(s2,t2):
            Union(i,j)

    s=s2
    t=t2

ALIST=[[] for i in range(N)]

for i in range(N):
    ALIST[find(i)].append(i)

ANS=[-1]*N

for i in range(N):
    for a in ALIST[i]:
        ANS[a]=len(ALIST[i])

for a in ANS:
    print(a)
0