結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-14 22:19:39 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,501 bytes |
| コンパイル時間 | 278 ms |
| コンパイル使用メモリ | 13,056 KB |
| 実行使用メモリ | 32,864 KB |
| 最終ジャッジ日時 | 2024-10-10 15:40:32 |
| 合計ジャッジ時間 | 9,158 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 WA * 18 |
ソースコード
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))