結果
問題 | No.2179 Planet Traveler |
ユーザー | MasKoaTS |
提出日時 | 2024-12-03 15:06:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 736 ms / 3,000 ms |
コード長 | 2,014 bytes |
コンパイル時間 | 508 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 127,944 KB |
最終ジャッジ日時 | 2024-12-03 15:06:13 |
合計ジャッジ時間 | 13,163 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,224 KB |
testcase_02 | AC | 42 ms
52,608 KB |
testcase_03 | AC | 43 ms
52,480 KB |
testcase_04 | AC | 42 ms
52,736 KB |
testcase_05 | AC | 42 ms
52,352 KB |
testcase_06 | AC | 42 ms
52,480 KB |
testcase_07 | AC | 43 ms
52,480 KB |
testcase_08 | AC | 51 ms
59,648 KB |
testcase_09 | AC | 53 ms
60,032 KB |
testcase_10 | AC | 51 ms
59,264 KB |
testcase_11 | AC | 652 ms
123,436 KB |
testcase_12 | AC | 695 ms
126,992 KB |
testcase_13 | AC | 703 ms
127,372 KB |
testcase_14 | AC | 703 ms
127,772 KB |
testcase_15 | AC | 662 ms
127,944 KB |
testcase_16 | AC | 663 ms
127,820 KB |
testcase_17 | AC | 736 ms
127,736 KB |
testcase_18 | AC | 715 ms
127,860 KB |
testcase_19 | AC | 685 ms
126,984 KB |
testcase_20 | AC | 145 ms
82,944 KB |
testcase_21 | AC | 711 ms
121,596 KB |
testcase_22 | AC | 466 ms
107,088 KB |
testcase_23 | AC | 370 ms
100,612 KB |
testcase_24 | AC | 617 ms
115,752 KB |
testcase_25 | AC | 450 ms
104,272 KB |
testcase_26 | AC | 631 ms
125,320 KB |
testcase_27 | AC | 165 ms
83,200 KB |
testcase_28 | AC | 298 ms
94,788 KB |
testcase_29 | AC | 597 ms
115,740 KB |
ソースコード
import sys import math input = sys.stdin.readline """ Union-Find ref : https://algo-logic.info/union-find-tree/ """ class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n self.group_members = {} def find(self, x): if(self.parents[x] < 0): return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if(x == y): return if(self.parents[x] > self.parents[y]): x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return (self.find(x) == self.find(y)) def size(self, x): return -self.parents[self.find(x)] def roots(self): return [i for i, x in enumerate(self.parents) if(x < 0)] def build_group_members(self): self.group_members = { x : [] for x in self.roots() } for x in range(self.n): self.group_members[self.find(x)].append(x) return self.group_members def isqrt(n): rn = math.sqrt(n) ok = max(0, int(rn - 2)) ng = int(rn + 2) while(abs(ok - ng) > 1): mid = (ok + ng) // 2 if(mid ** 2 <= n): ok = mid else: ng = mid return ok ''' Main Code ''' n = int(input()) planets = [list(map(int, input().split())) for _ in [0] * n] edges = [] 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) ** 2 if(t1 != t2): r1 = x1 ** 2 + y1 ** 2 r2 = x2 ** 2 + y2 ** 2 d = r1 + r2 - isqrt(4 * r1 * r2) edges.append((i, j, d)) edges.sort(key=lambda x : x[2]) uni = UnionFind(n) ans = 0 for x, y, z in edges: ans = z uni.unite(x, y) if not(uni.same(0, n - 1)): continue break print(ans)