結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
57,984 KB
testcase_01 AC 41 ms
52,736 KB
testcase_02 AC 44 ms
52,480 KB
testcase_03 AC 42 ms
52,608 KB
testcase_04 AC 40 ms
52,864 KB
testcase_05 AC 40 ms
52,736 KB
testcase_06 AC 39 ms
52,352 KB
testcase_07 AC 39 ms
52,864 KB
testcase_08 AC 36 ms
52,608 KB
testcase_09 AC 39 ms
52,736 KB
testcase_10 AC 38 ms
52,608 KB
testcase_11 AC 39 ms
52,480 KB
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 149 ms
76,032 KB
testcase_23 AC 112 ms
76,544 KB
testcase_24 AC 153 ms
76,288 KB
testcase_25 AC 152 ms
76,800 KB
testcase_26 AC 134 ms
76,804 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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(s2,t):
            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