結果

問題 No.168 ものさし
ユーザー dice4084dice4084
提出日時 2023-01-03 20:23:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,824 KB
実行使用メモリ 79,544 KB
最終ジャッジ日時 2023-08-18 00:45:12
合計ジャッジ時間 5,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
79,104 KB
testcase_01 AC 71 ms
71,380 KB
testcase_02 AC 71 ms
71,568 KB
testcase_03 AC 74 ms
71,676 KB
testcase_04 AC 73 ms
71,428 KB
testcase_05 AC 73 ms
71,332 KB
testcase_06 AC 82 ms
76,344 KB
testcase_07 AC 73 ms
71,376 KB
testcase_08 AC 74 ms
71,532 KB
testcase_09 AC 130 ms
77,984 KB
testcase_10 AC 148 ms
77,820 KB
testcase_11 AC 211 ms
78,784 KB
testcase_12 AC 330 ms
79,152 KB
testcase_13 AC 393 ms
79,344 KB
testcase_14 AC 376 ms
78,716 KB
testcase_15 AC 73 ms
71,316 KB
testcase_16 AC 131 ms
78,088 KB
testcase_17 AC 147 ms
78,604 KB
testcase_18 AC 162 ms
78,256 KB
testcase_19 AC 386 ms
78,572 KB
testcase_20 AC 336 ms
78,956 KB
testcase_21 AC 354 ms
79,544 KB
testcase_22 AC 343 ms
79,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import ceil

input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.par = [-1] * n
        self.rank = [0] * n
        self.siz = [1] * n

    def root(self, x):
        if self.par[x] == -1:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        if self.is_same(x, y):
            return False

        rx = self.root(x)
        ry = self.root(y)
        if self.rank[rx] < self.rank[ry]:
            rx, ry = ry, rx
        elif self.rank[rx] == self.rank[ry]:
            self.rank[rx] += 1

        self.par[ry] = rx
        self.siz[rx] += self.siz[ry]
        return True


n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]

l = 0
r = 2 * 10**9
for _ in range(35):
    mid = ceil((l + r) / 20) * 10
    uf = UnionFind(n)
    for i in range(n - 1):
        ix, iy = points[i]
        for j in range(i + 1, n):
            jx, jy = points[j]
            if (ix - jx) ** 2 + (iy - jy) ** 2 <= mid**2:
                uf.unite(i, j)

    if uf.is_same(0, n - 1):
        r = mid
    else:
        l = mid

print(r)
0