結果

問題 No.1170 Never Want to Walk
ユーザー marroncastlemarroncastle
提出日時 2020-08-14 22:19:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 32,732 KB
最終ジャッジ日時 2024-04-18 22:11:03
合計ジャッジ時間 9,003 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 31 ms
10,880 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 WA -
testcase_11 AC 32 ms
10,880 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 29 ms
10,752 KB
testcase_23 AC 30 ms
10,880 KB
testcase_24 AC 30 ms
10,880 KB
testcase_25 AC 30 ms
10,752 KB
testcase_26 AC 30 ms
10,880 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 583 ms
31,568 KB
testcase_34 WA -
testcase_35 AC 428 ms
32,216 KB
testcase_36 AC 434 ms
31,636 KB
testcase_37 AC 380 ms
32,136 KB
testcase_38 AC 393 ms
32,732 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 not uf.same(i-1,i) and 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