結果

問題 No.1170 Never Want to Walk
ユーザー brthyyjpbrthyyjp
提出日時 2020-11-08 14:42:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 377 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 104,828 KB
最終ジャッジ日時 2023-09-29 21:12:34
合計ジャッジ時間 9,023 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
70,884 KB
testcase_01 AC 64 ms
70,892 KB
testcase_02 AC 64 ms
71,304 KB
testcase_03 AC 71 ms
71,172 KB
testcase_04 AC 69 ms
71,084 KB
testcase_05 AC 68 ms
71,220 KB
testcase_06 AC 62 ms
71,236 KB
testcase_07 AC 63 ms
71,336 KB
testcase_08 AC 62 ms
70,888 KB
testcase_09 AC 65 ms
71,408 KB
testcase_10 AC 60 ms
71,308 KB
testcase_11 AC 60 ms
71,236 KB
testcase_12 AC 79 ms
75,864 KB
testcase_13 AC 85 ms
76,052 KB
testcase_14 AC 82 ms
76,116 KB
testcase_15 AC 80 ms
75,968 KB
testcase_16 AC 88 ms
76,076 KB
testcase_17 AC 87 ms
76,108 KB
testcase_18 AC 86 ms
76,096 KB
testcase_19 AC 89 ms
75,988 KB
testcase_20 AC 87 ms
75,788 KB
testcase_21 AC 81 ms
76,088 KB
testcase_22 AC 83 ms
76,016 KB
testcase_23 AC 88 ms
76,620 KB
testcase_24 AC 82 ms
76,140 KB
testcase_25 AC 80 ms
75,976 KB
testcase_26 AC 86 ms
76,236 KB
testcase_27 AC 346 ms
104,384 KB
testcase_28 AC 335 ms
103,932 KB
testcase_29 AC 377 ms
104,652 KB
testcase_30 AC 341 ms
104,540 KB
testcase_31 AC 341 ms
104,444 KB
testcase_32 AC 240 ms
104,148 KB
testcase_33 AC 285 ms
104,104 KB
testcase_34 AC 300 ms
104,828 KB
testcase_35 AC 301 ms
104,756 KB
testcase_36 AC 243 ms
104,644 KB
testcase_37 AC 279 ms
103,996 KB
testcase_38 AC 273 ms
104,456 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 reversed(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