結果

問題 No.1170 Never Want to Walk
ユーザー titiatitia
提出日時 2020-08-14 22:43:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,051 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 51,536 KB
最終ジャッジ日時 2024-04-18 22:34:06
合計ジャッジ時間 15,669 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 29 ms
10,880 KB
testcase_12 AC 34 ms
10,880 KB
testcase_13 AC 34 ms
11,008 KB
testcase_14 AC 35 ms
11,136 KB
testcase_15 AC 35 ms
10,880 KB
testcase_16 AC 34 ms
11,008 KB
testcase_17 AC 35 ms
10,880 KB
testcase_18 AC 33 ms
10,880 KB
testcase_19 AC 34 ms
11,008 KB
testcase_20 AC 34 ms
10,880 KB
testcase_21 AC 33 ms
11,008 KB
testcase_22 AC 35 ms
11,136 KB
testcase_23 AC 35 ms
11,008 KB
testcase_24 AC 35 ms
11,008 KB
testcase_25 AC 35 ms
11,008 KB
testcase_26 AC 35 ms
10,880 KB
testcase_27 AC 1,009 ms
50,304 KB
testcase_28 AC 1,014 ms
49,756 KB
testcase_29 AC 1,029 ms
51,256 KB
testcase_30 AC 1,038 ms
50,844 KB
testcase_31 AC 1,001 ms
49,884 KB
testcase_32 AC 999 ms
50,128 KB
testcase_33 AC 1,006 ms
49,776 KB
testcase_34 AC 1,027 ms
50,976 KB
testcase_35 AC 1,051 ms
51,100 KB
testcase_36 AC 1,027 ms
49,724 KB
testcase_37 AC 990 ms
50,292 KB
testcase_38 AC 1,027 ms
51,536 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