結果

問題 No.168 ものさし
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-28 18:50:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 80,060 KB
最終ジャッジ日時 2023-08-25 21:01:54
合計ジャッジ時間 10,386 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 292 ms
78,728 KB
testcase_01 AC 90 ms
71,748 KB
testcase_02 AC 91 ms
71,724 KB
testcase_03 AC 90 ms
71,720 KB
testcase_04 AC 92 ms
71,744 KB
testcase_05 AC 93 ms
71,964 KB
testcase_06 AC 109 ms
77,124 KB
testcase_07 AC 91 ms
71,708 KB
testcase_08 AC 93 ms
71,740 KB
testcase_09 AC 142 ms
78,188 KB
testcase_10 AC 166 ms
78,428 KB
testcase_11 AC 325 ms
78,752 KB
testcase_12 AC 694 ms
79,452 KB
testcase_13 AC 973 ms
80,060 KB
testcase_14 AC 918 ms
79,256 KB
testcase_15 AC 95 ms
76,084 KB
testcase_16 AC 135 ms
77,912 KB
testcase_17 AC 150 ms
78,032 KB
testcase_18 AC 180 ms
77,952 KB
testcase_19 AC 972 ms
79,016 KB
testcase_20 AC 1,012 ms
79,668 KB
testcase_21 AC 821 ms
79,832 KB
testcase_22 AC 1,000 ms
79,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

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()
0