結果

問題 No.168 ものさし
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-28 18:46:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,935 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 16,768 KB
最終ジャッジ日時 2024-04-16 18:10:53
合計ジャッジ時間 10,797 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,774 ms
16,768 KB
testcase_01 AC 32 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 31 ms
11,136 KB
testcase_04 AC 32 ms
11,136 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 32 ms
11,136 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 32 ms
11,008 KB
testcase_09 AC 111 ms
11,136 KB
testcase_10 AC 359 ms
11,136 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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()
0