結果
| 問題 |
No.2179 Planet Traveler
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:27:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,600 bytes |
| コンパイル時間 | 267 ms |
| コンパイル使用メモリ | 81,980 KB |
| 実行使用メモリ | 123,460 KB |
| 最終ジャッジ日時 | 2025-04-15 23:28:37 |
| 合計ジャッジ時間 | 4,312 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 WA * 1 |
ソースコード
import math
import heapq
def main():
n = int(input())
planets = []
for _ in range(n):
x, y, t = map(int, input().split())
planets.append((x, y, t))
# Precompute radii for each planet
r = []
for x, y, t in planets:
r_sq = x * x + y * y
r_i = math.sqrt(r_sq)
r.append(r_i)
# Precompute adjacency list with min_dist_sq for each pair
adj = [[] for _ in range(n)]
for i in range(n):
xi, yi, ti = planets[i]
ri = r[i]
for j in range(n):
if i == j:
continue
xj, yj, tj = planets[j]
rj = r[j]
if ti != tj:
min_dist_sq = (ri - rj) ** 2
else:
dx = xi - xj
dy = yi - yj
min_dist_sq = dx * dx + dy * dy
adj[i].append((j, min_dist_sq))
# Dijkstra's algorithm to find the minimal maximum edge weight
INF = float('inf')
dist = [INF] * n
dist[0] = 0.0
heap = []
heapq.heappush(heap, (0.0, 0))
while heap:
current_max, u = heapq.heappop(heap)
if u == n - 1:
print(math.ceil(current_max))
return
if current_max > dist[u]:
continue
for v, weight in adj[u]:
new_max = max(current_max, weight)
if new_max < dist[v]:
dist[v] = new_max
heapq.heappush(heap, (new_max, v))
# If no path found (should not happen as per problem constraints)
print(-1)
if __name__ == "__main__":
main()
lam6er