結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-30 21:25:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,089 bytes |
| コンパイル時間 | 1,090 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 65,536 KB |
| 最終ジャッジ日時 | 2024-12-30 21:25:28 |
| 合計ジャッジ時間 | 6,075 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 37 |
ソースコード
import bisect
from collections import deque
from sortedcontainers import SortedSet
N,A,B=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
ne=[-1]*N
def root(N):
if ne[N]<0:
return N
else:
ne[N]=root(ne[N])
return ne[N]
def merge(x,y):
x,y=root(x),root(y)
if x==y:
return
if ne[x]>ne[y]:
x,y=y,x
ne[x]+=ne[y]
ne[y]=x
def same(x,y):
return root(x)==root(y)
q=deque()
stp=set()
n={v:i for i,v in enumerate(x)}
x=SortedSet(x)
haiki=[]
while x:
now=x.pop(0)
q.append(now)
haiki=[]
while q:
now=q.popleft()
a=x.bisect_right(now-A)
b=x.bisect_left(now-B)
c=x.bisect_left(now+A)
d=x.bisect_right(now+B)
for v in range(b,a):
if same(n[now],n[x[v]]):
continue
haiki.append(x[v])
merge(n[now],n[x[v]])
q.append(x[v])
for v in range(c,d):
if same(n[now],n[x[v]]):
continue
haiki.append(x[v])
merge(n[now],n[x[v]])
q.append(x[v])
while haiki:
x.discard(haiki.pop())
for i in range(N):
print(-ne[root(i)])