結果
| 問題 |
No.168 ものさし
|
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-05-28 18:46:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,935 bytes |
| コンパイル時間 | 236 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 17,828 KB |
| 最終ジャッジ日時 | 2024-10-07 17:31:47 |
| 合計ジャッジ時間 | 10,965 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 2 -- * 10 |
ソースコード
#!/usr/bin/env python3
import array
import collections
import itertools
import sys
MAX_L = 1414213563
Point = collections.namedtuple("Point", "index x y")
def are_close(point1, point2, tol):
dx = point1.x - point2.x
dy = point1.y - point2.y
return dx * dx + dy * dy <= tol * tol
def bisection(f, left, right):
while left < right:
mid = (left + right) // 2
if f(mid):
right = mid
else:
left = mid + 1
return right
class UnionFind(object):
def __init__(self, number_of_nodes, typecode="I"):
self.par = array.array(typecode, range(number_of_nodes))
self.rank = array.array(typecode, (0 for i in range(number_of_nodes)))
def root(self, node):
if self.par[node] == node:
return node
else:
r = self.root(self.par[node])
self.par[node] = r # 経路圧縮
return r
def in_the_same_set(self, node1, node2):
return self.root(node1) == self.root(node2)
def unite(self, node1, node2):
x = self.root(node1)
y = self.root(node2)
if x == y:
pass
elif self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def can_concat_all_points(n, points, ruler_length):
uf = UnionFind(n)
for p1, p2 in itertools.combinations(points, 2):
if are_close(p1, p2, ruler_length):
uf.unite(p1.index, p2.index)
return uf.in_the_same_set(0, n - 1)
def compute_min(n, points):
def f(x):
return can_concat_all_points(n, points, x)
x0 = bisection(f, 0, MAX_L)
return (x0 + 9) // 10 * 10
def main():
n = int(input())
points = [Point(i, *map(int, input().split())) for i in range(n)]
print(compute_min(n, points))
if __name__ == '__main__':
main()
はむ吉🐹