結果
問題 | No.168 ものさし |
ユーザー |
|
提出日時 | 2020-05-10 09:13:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,760 ms / 2,000 ms |
コード長 | 1,456 bytes |
コンパイル時間 | 445 ms |
コンパイル使用メモリ | 82,660 KB |
実行使用メモリ | 243,164 KB |
最終ジャッジ日時 | 2025-04-19 21:05:20 |
合計ジャッジ時間 | 11,417 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
import itertoolsfrom math import isqrtfrom collections import defaultdictceil = lambda a, b: (a + b - 1) // bceil_sq = lambda n: 1 + isqrt(n - 1)class UnionFind:def __init__(self, n):self.n = nself.parent = [i for i in range(n)]self.height = [1] * nself.size = [1] * ndef find(self, x):if self.parent[x] == x:return xelse:self.parent[x] = self.find(self.parent[x])return self.parent[x]def unite(self, x, y):x = self.find(x)y = self.find(y)if x != y:if self.height[x] < self.height[y]:self.parent[x] = yself.size[y] += self.size[x]else:self.parent[y] = xself.size[x] += self.size[y]if self.height[x] == self.height[y]:self.height[x] += 1def issame(self, x, y):return self.find(x) == self.find(y)N = int(input())P = [tuple(map(int, input().split())) for _ in range(N)]d = defaultdict(list)for p1, p2 in itertools.combinations(range(N), 2):dist = ceil_sq((P[p1][0] - P[p2][0]) ** 2 + (P[p1][1] - P[p2][1]) ** 2)d[ceil(dist, 10) * 10].append((p1, p2))lst = sorted(list(d.items()))lst.sort()uf = UnionFind(N)for dist, points in lst:for p1, p2 in points:uf.unite(p1, p2)if uf.issame(0, N - 1):print(dist)break