結果

問題 No.1170 Never Want to Walk
ユーザー prd_xxxprd_xxx
提出日時 2020-08-15 13:09:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 865 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 36,824 KB
最終ジャッジ日時 2024-04-19 00:54:41
合計ジャッジ時間 13,586 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,008 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 29 ms
11,008 KB
testcase_03 AC 29 ms
11,008 KB
testcase_04 AC 29 ms
10,880 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 28 ms
11,008 KB
testcase_07 AC 27 ms
10,880 KB
testcase_08 AC 28 ms
11,008 KB
testcase_09 AC 28 ms
11,008 KB
testcase_10 AC 29 ms
11,008 KB
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 33 ms
11,136 KB
testcase_13 AC 33 ms
11,136 KB
testcase_14 AC 33 ms
11,136 KB
testcase_15 AC 32 ms
11,008 KB
testcase_16 AC 33 ms
11,136 KB
testcase_17 AC 33 ms
11,136 KB
testcase_18 AC 33 ms
11,136 KB
testcase_19 AC 33 ms
11,136 KB
testcase_20 AC 33 ms
11,008 KB
testcase_21 AC 33 ms
11,136 KB
testcase_22 AC 34 ms
11,136 KB
testcase_23 AC 34 ms
11,008 KB
testcase_24 AC 34 ms
11,136 KB
testcase_25 AC 34 ms
11,136 KB
testcase_26 AC 34 ms
11,264 KB
testcase_27 AC 794 ms
34,992 KB
testcase_28 AC 796 ms
34,688 KB
testcase_29 AC 801 ms
35,608 KB
testcase_30 AC 803 ms
35,600 KB
testcase_31 AC 798 ms
34,816 KB
testcase_32 AC 831 ms
35,920 KB
testcase_33 AC 831 ms
35,640 KB
testcase_34 AC 856 ms
36,660 KB
testcase_35 AC 840 ms
36,484 KB
testcase_36 AC 835 ms
35,756 KB
testcase_37 AC 830 ms
36,172 KB
testcase_38 AC 865 ms
36,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,A,B = map(int,input().split())
X = list(map(int,input().split()))

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self._size = [1] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self._size[ra] < self._size[rb]: ra,rb = rb,ra
        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        self.count += 1
    def size(self,a):
        return self._size[self.root(a)]

uf = UnionFind(N)
imos = [0] * N
from bisect import bisect,bisect_left
for i,x in enumerate(X):
    j = bisect_left(X, x+A)
    k = bisect(X, x+B) - 1
    if j > k: continue
    if j < N:
        uf.unite(i,j)
        imos[j] += 1
        imos[k] -= 1

for i in range(N-1):
    imos[i+1] += imos[i]
for i,a in enumerate(imos[:-1]):
    if a:
        uf.unite(i,i+1)

ans = [uf.size(i) for i in range(N)]
print(*ans, sep='\n')
0