結果
問題 | No.2179 Planet Traveler |
ユーザー |
![]() |
提出日時 | 2024-12-03 15:13:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 526 ms / 3,000 ms |
コード長 | 1,085 bytes |
コンパイル時間 | 202 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 148,568 KB |
最終ジャッジ日時 | 2024-12-03 15:13:38 |
合計ジャッジ時間 | 7,355 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
import sysimport mathimport heapq as hqinput = sys.stdin.readlineINF = 4611686018427387903def isqrt(n):rn = math.sqrt(n)ok = max(0, int(rn - 2))ng = int(rn + 2)while(abs(ok - ng) > 1):mid = (ok + ng) // 2if(mid ** 2 <= n):ok = midelse:ng = midreturn ok'''Main Code'''n = int(input())planets = [list(map(int, input().split())) for _ in [0] * n]graph = [[] for _ in [0] * n]for i in range(n - 1):for j in range(i + 1, n):x1, y1, t1 = planets[i]x2, y2, t2 = planets[j]d = (x1 - x2) ** 2 + (y1 - y2) ** 2if(t1 != t2):r1 = x1 ** 2 + y1 ** 2r2 = x2 ** 2 + y2 ** 2d = r1 + r2 - isqrt(4 * r1 * r2)graph[i].append((j, d))graph[j].append((i, d))dp = [INF] * nque = [(0, 0)]while(que):c, v = hq.heappop(que)if(dp[v] <= c):continuedp[v] = cif(v == n - 1):breakfor nv, nd in graph[v]:hq.heappush(que, (max(c, nd), nv))ans = dp[n - 1]print(ans)