Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created February 12, 2026 08:50
Show Gist options
  • Select an option

  • Save maehrm/616fd6d91d874f11c60e350d9e47ef0a to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/616fd6d91d874f11c60e350d9e47ef0a to your computer and use it in GitHub Desktop.
from collections import deque
def check(s):
for i in range(N):
if bfs(i, s):
return True
return False
def bfs(start, s): # start地点からジャンプ力sで全ての点に到達可能か?
que = deque([start])
visits = [False] * N
visits[start] = True
while que:
cur = que.popleft()
for nxt in range(N):
if visits[nxt]:
continue
if can_jump(cur, nxt, s):
que.append(nxt)
visits[nxt] = True
return all(visits)
def can_jump(i, j, s): # i番目からj番目のジャンプ台にジャンプできるか?
xi, yi, pi = points[i]
xj, yj, pj = points[j]
return pi * s >= abs(xi - xj) + abs(yi - yj)
N = int(input())
points = []
for i in range(N):
x, y, P = map(int, input().split())
points.append((x, y, P))
ng, ok = 0, 10**10
while ok - ng > 1:
s = (ng + ok) // 2
if check(s):
ok = s
else:
ng = s
print(ok)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment