結果

問題 No.1170 Never Want to Walk
ユーザー marroncastlemarroncastle
提出日時 2020-08-14 22:37:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,478 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 32,868 KB
最終ジャッジ日時 2024-04-18 22:27:34
合計ジャッジ時間 9,425 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,008 KB
testcase_01 AC 32 ms
11,008 KB
testcase_02 AC 32 ms
11,008 KB
testcase_03 AC 32 ms
11,136 KB
testcase_04 WA -
testcase_05 AC 32 ms
11,136 KB
testcase_06 AC 32 ms
11,136 KB
testcase_07 AC 32 ms
11,008 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 33 ms
11,008 KB
testcase_10 AC 32 ms
11,136 KB
testcase_11 AC 33 ms
11,008 KB
testcase_12 WA -
testcase_13 AC 35 ms
11,136 KB
testcase_14 AC 36 ms
11,008 KB
testcase_15 AC 35 ms
11,008 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 34 ms
11,008 KB
testcase_19 AC 35 ms
11,136 KB
testcase_20 AC 35 ms
11,008 KB
testcase_21 WA -
testcase_22 AC 35 ms
11,008 KB
testcase_23 AC 35 ms
11,008 KB
testcase_24 AC 34 ms
11,008 KB
testcase_25 AC 34 ms
11,008 KB
testcase_26 AC 35 ms
11,008 KB
testcase_27 AC 651 ms
32,104 KB
testcase_28 AC 648 ms
31,796 KB
testcase_29 AC 655 ms
32,676 KB
testcase_30 AC 656 ms
32,452 KB
testcase_31 AC 639 ms
31,860 KB
testcase_32 WA -
testcase_33 AC 588 ms
31,956 KB
testcase_34 WA -
testcase_35 AC 479 ms
32,476 KB
testcase_36 AC 469 ms
31,892 KB
testcase_37 AC 408 ms
32,260 KB
testcase_38 AC 429 ms
32,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
    return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
          x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def num_roots(self):
    return len([i for i, x in enumerate(self.parents) if x < 0])

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def num_members(self,x):
    return abs(self.parents[self.find(x)])

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

from bisect import *
def uni(i,A,B):
  ind = bisect_left(X,X[i]+A)
  while ind<N and X[ind]-X[i]<=B:
    uf.union(i,ind)
    ind += 1
  return ind-1
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
uf = UnionFind(N)
ind = uni(0,A,B)
for i in range(1,N):
  if X[i]+A>X[ind]:
    ind = uni(i,A,B)
  else:
    uf.union(i,ind)
    while ind+1<N and X[ind+1]<=X[i]+B:
      ind += 1
      uf.union(i,ind)
  if ind==N-1:
    break
for i in range(N):
  print(uf.num_members(i))
0