結果
問題 | No.2179 Planet Traveler |
ユーザー | MasKoaTS |
提出日時 | 2022-08-03 14:00:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,511 bytes |
コンパイル時間 | 345 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 128,048 KB |
最終ジャッジ日時 | 2024-05-07 20:26:37 |
合計ジャッジ時間 | 12,286 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
52,608 KB |
testcase_01 | AC | 44 ms
52,864 KB |
testcase_02 | AC | 47 ms
52,352 KB |
testcase_03 | AC | 45 ms
52,864 KB |
testcase_04 | AC | 47 ms
52,992 KB |
testcase_05 | AC | 43 ms
52,520 KB |
testcase_06 | AC | 40 ms
52,608 KB |
testcase_07 | AC | 41 ms
52,864 KB |
testcase_08 | AC | 44 ms
53,760 KB |
testcase_09 | AC | 47 ms
59,136 KB |
testcase_10 | AC | 44 ms
53,760 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 689 ms
127,716 KB |
testcase_15 | AC | 694 ms
127,720 KB |
testcase_16 | AC | 683 ms
128,048 KB |
testcase_17 | AC | 711 ms
126,872 KB |
testcase_18 | AC | 723 ms
127,180 KB |
testcase_19 | AC | 667 ms
127,420 KB |
testcase_20 | AC | 136 ms
83,260 KB |
testcase_21 | AC | 691 ms
124,236 KB |
testcase_22 | AC | 458 ms
106,852 KB |
testcase_23 | AC | 331 ms
95,332 KB |
testcase_24 | AC | 575 ms
121,988 KB |
testcase_25 | AC | 444 ms
108,488 KB |
testcase_26 | AC | 594 ms
124,368 KB |
testcase_27 | AC | 108 ms
75,392 KB |
testcase_28 | AC | 271 ms
92,568 KB |
testcase_29 | AC | 605 ms
122,240 KB |
ソースコード
# WA(?) import sys, math input = sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if(self.parents[x] < 0): return x 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 members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def isqrt(n): rn = math.sqrt(n) ok = max(0, int(rn - 2)) ng = int(rn + 2) while(ng - ok > 1): k = (ok + ng) >> 1 if(k * k <= n): ok = k else: ng = k return ok """ Main Code """ n = int(input()) planet = [list(map(int, input().split())) for _ in [0] * n] edge = [] for i in range(0, n-1): for j in range(i+1, n): p1 = planet[i] p2 = planet[j] d = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 if(p1[2] != p2[2]): r1 = p1[0] ** 2 + p1[1] ** 2 r2 = p2[0] ** 2 + p2[1] ** 2 d = r1 + r2 - int(2 * math.sqrt(r1) * math.sqrt(r2)) edge.append((i, j, d)) edge.sort(key = lambda x : x[2]) uni = UnionFind(n) ans = 0 for a, b, c in edge: ans = c uni.unite(a, b) if(uni.same(0, n-1)): break print(ans)