結果

問題 No.1170 Never Want to Walk
ユーザー しもりん
提出日時 2024-10-25 03:41:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 851 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 38,984 KB
最終ジャッジ日時 2024-10-25 03:41:15
合計ジャッジ時間 13,767 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,Counter,deque
from heapq import heappush,heappop,heapify
from bisect import bisect,bisect_left
from itertools import product,permutations,combinations,combinations_with_replacement
from math import gcd
import sys
from functools import lru_cache
if len(sys.argv)==2:sys.stdin=open(sys.argv[1])
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

N,A,B=map(int,input().split())
X=list(map(int,input().split()))
C=[-1]*N
c=0
q=[]
ans=dict()
for i,x in enumerate(X):
	if C[i]<0:
		res=0
		q.append(i)
		C[i]=c
		while q:
			i=q.pop()
			res+=1
			x=X[i]
			j=bisect(X,x-A)-1
			while j>=0 and x-X[j]<=B:
				if C[j]<0:
					C[j]=c
					q.append(j)
				j-=1
			j=bisect_left(X,x+A)
			while j<N and X[j]-x<=B:
				if C[j]<0:
					C[j]=c
					q.append(j)
				j+=1
		ans[c]=res
		c+=1
	else:
		res=ans[C[i]]
	print(res)
0