結果
問題 | No.1170 Never Want to Walk |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:48:45 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,647 bytes |
コンパイル時間 | 382 ms |
コンパイル使用メモリ | 82,772 KB |
実行使用メモリ | 104,408 KB |
最終ジャッジ日時 | 2025-03-26 15:49:57 |
合計ジャッジ時間 | 9,512 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 TLE * 1 -- * 6 |
ソースコード
import bisectfrom collections import dequen, a, b = map(int, input().split())x = list(map(int, input().split()))visited = [False] * nans = [0] * nfor i in range(n):if not visited[i]:q = deque()component = []q.append(i)visited[i] = Truecomponent.append(i)while q:current = q.popleft()current_x = x[current]# Process right allowed range (current_x + a to current_x + b)lower_right = current_x + aupper_right = current_x + bleft_idx = bisect.bisect_left(x, lower_right)right_idx = bisect.bisect_right(x, upper_right) - 1if left_idx <= right_idx:for k in range(left_idx, right_idx + 1):if not visited[k]:visited[k] = Truecomponent.append(k)q.append(k)# Process left allowed range (current_x - b to current_x - a)lower_left = current_x - bupper_left = current_x - aleft_left_idx = bisect.bisect_left(x, lower_left)right_left_idx = bisect.bisect_right(x, upper_left) - 1if left_left_idx <= right_left_idx:for k in range(left_left_idx, right_left_idx + 1):if not visited[k]:visited[k] = Truecomponent.append(k)q.append(k)size = len(component)for node in component:ans[node] = sizefor num in ans:print(num)