結果
問題 | No.2179 Planet Traveler |
ユーザー | tassei903 |
提出日時 | 2023-01-06 23:12:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 806 ms / 3,000 ms |
コード長 | 2,329 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 78,972 KB |
最終ジャッジ日時 | 2024-05-07 22:59:33 |
合計ジャッジ時間 | 12,306 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,400 KB |
testcase_01 | AC | 43 ms
54,656 KB |
testcase_02 | AC | 39 ms
54,400 KB |
testcase_03 | AC | 39 ms
54,272 KB |
testcase_04 | AC | 41 ms
54,656 KB |
testcase_05 | AC | 41 ms
54,400 KB |
testcase_06 | AC | 41 ms
54,400 KB |
testcase_07 | AC | 54 ms
66,432 KB |
testcase_08 | AC | 101 ms
76,684 KB |
testcase_09 | AC | 107 ms
77,440 KB |
testcase_10 | AC | 90 ms
76,924 KB |
testcase_11 | AC | 373 ms
77,680 KB |
testcase_12 | AC | 718 ms
77,184 KB |
testcase_13 | AC | 762 ms
78,608 KB |
testcase_14 | AC | 271 ms
77,672 KB |
testcase_15 | AC | 275 ms
77,292 KB |
testcase_16 | AC | 271 ms
77,424 KB |
testcase_17 | AC | 806 ms
78,388 KB |
testcase_18 | AC | 791 ms
78,256 KB |
testcase_19 | AC | 785 ms
77,952 KB |
testcase_20 | AC | 237 ms
77,440 KB |
testcase_21 | AC | 730 ms
78,216 KB |
testcase_22 | AC | 567 ms
78,372 KB |
testcase_23 | AC | 468 ms
77,824 KB |
testcase_24 | AC | 646 ms
78,332 KB |
testcase_25 | AC | 538 ms
78,300 KB |
testcase_26 | AC | 712 ms
78,208 KB |
testcase_27 | AC | 231 ms
77,640 KB |
testcase_28 | AC | 416 ms
78,208 KB |
testcase_29 | AC | 665 ms
78,972 KB |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n 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 union(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 size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) 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 group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) n = ni() x,y,t = zip(*[na() for i in range(n)]) ok = 10**10 ng = -1 while ok - ng > 1: d = ok+ng>>1 uf = UnionFind(n) for i in range(n): for j in range(i+1, n): if t[i] == t[j]: if (x[i]-x[j])**2+(y[i]-y[j])**2 <= d: uf.union(i, j) else: d1, d2 = min(x[i]**2+y[i]**2,x[j]**2+y[j]**2),max(x[i]**2+y[i]**2,x[j]**2+y[j]**2) #print(d1,d2) if (d1 + d2 - d)**2 <= 4 * d1 *d2 or d1 + d2 - d <= 0: uf.union(i, j) #print(d, uf.all_group_members()) if uf.same(0, n-1): ok = d else: ng = d print(ok)