結果

問題 No.1170 Never Want to Walk
ユーザー brthyyjpbrthyyjp
提出日時 2020-11-08 14:39:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 105,172 KB
最終ジャッジ日時 2023-09-29 21:12:24
合計ジャッジ時間 8,996 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,116 KB
testcase_01 AC 75 ms
71,632 KB
testcase_02 AC 74 ms
71,436 KB
testcase_03 AC 75 ms
71,408 KB
testcase_04 AC 76 ms
71,400 KB
testcase_05 AC 76 ms
71,104 KB
testcase_06 AC 75 ms
71,400 KB
testcase_07 AC 75 ms
71,112 KB
testcase_08 AC 75 ms
71,336 KB
testcase_09 AC 76 ms
71,100 KB
testcase_10 AC 74 ms
71,372 KB
testcase_11 AC 76 ms
71,364 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 96 ms
76,268 KB
testcase_23 AC 100 ms
76,180 KB
testcase_24 AC 97 ms
75,948 KB
testcase_25 AC 95 ms
76,172 KB
testcase_26 AC 100 ms
76,016 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 288 ms
104,404 KB
testcase_33 AC 305 ms
104,216 KB
testcase_34 AC 326 ms
104,728 KB
testcase_35 AC 334 ms
104,788 KB
testcase_36 AC 284 ms
104,828 KB
testcase_37 AC 307 ms
103,680 KB
testcase_38 AC 279 ms
104,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

par = [-1]* n
rank = [0]*n

import bisect
for i in range(n):
    x = X[i]
    l = bisect.bisect_left(X, x+a)
    r = bisect.bisect_right(X, x+b)
    for k in range(l, r):
        if Same(i, k, par):
            break
        Unite(i, k, par, rank)

ans = [0]*n
for i in range(n):
    ans[i] = Size(i, par)
print(*ans, sep='\n')
0