結果
問題 |
No.2179 Planet Traveler
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:13:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,603 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,028 KB |
実行使用メモリ | 90,620 KB |
最終ジャッジ日時 | 2025-03-20 21:14:34 |
合計ジャッジ時間 | 5,047 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 WA * 12 |
ソースコード
import math import heapq def main(): N = int(input()) X = [] Y = [] T = [] r_i = [] for _ in range(N): x, y, t = map(int, input().split()) X.append(x) Y.append(y) T.append(t) r = math.hypot(x, y) r_i.append(r) # Precompute distance matrix d_matrix = [[0.0] * N for _ in range(N)] for i in range(N): for j in range(N): if i == j: d_matrix[i][j] = 0.0 else: if T[i] == T[j]: dx = X[i] - X[j] dy = Y[i] - Y[j] d = math.hypot(dx, dy) else: d = abs(r_i[i] - r_i[j]) d_matrix[i][j] = d d_matrix[j][i] = d # since undirected # Dijkstra's algorithm to find minimal maximum edge 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: # Compute the square and round to integer print(int(round(current_max ** 2))) return if current_max > dist[u]: continue for v in range(N): if v == u: continue new_max = max(current_max, d_matrix[u][v]) if new_max < dist[v]: dist[v] = new_max heapq.heappush(heap, (new_max, v)) # If no path found (but problem states there is a path) print(0) if __name__ == "__main__": main()