結果

問題 No.168 ものさし
ユーザー matsu7874matsu7874
提出日時 2015-10-04 18:02:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,596 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 15,372 KB
最終ジャッジ日時 2023-09-27 02:00:54
合計ジャッジ時間 10,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 16 ms
8,052 KB
testcase_02 AC 16 ms
7,984 KB
testcase_03 AC 16 ms
8,120 KB
testcase_04 AC 17 ms
7,984 KB
testcase_05 AC 17 ms
8,060 KB
testcase_06 AC 17 ms
8,104 KB
testcase_07 AC 17 ms
8,012 KB
testcase_08 AC 16 ms
8,004 KB
testcase_09 AC 57 ms
7,988 KB
testcase_10 AC 166 ms
8,760 KB
testcase_11 AC 1,077 ms
14,072 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:

    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        group = []
        while self.table[x] >= 0:
            group.append(x)
            x = self.table[x]
        for g in group:
            self.table[g] = x
        return x

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
        return self.table[s1]


def distance2(px, py, qx, qy):
    return (px - qx) * (px - qx) + (py - qy) * (py - qy)


def acceptable(lenght):
    l = lenght * lenght
    uf = UnionFind(N)
    for i in range(N-1):
        for j in range(i+1,N):
            if D[i][j] <= l:
                uf.union(i, j)
    return uf.find(0) == uf.find(N - 1)


N = int(input())
P = []
for i in range(N):
    x, y = map(int, input().split())
    P.append((x, y))
D = [[0] * N for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        D[i][j] = distance2(P[i][0], P[i][1], P[j][0], P[j][1])
        D[j][i] = D[i][j]

lower_limit = 0
upper_limit = D[0][N-1]
while lower_limit < upper_limit:
    mid = (lower_limit + upper_limit) // 2
    if acceptable(mid):
        upper_limit = mid
    else:
        lower_limit = mid + 1
    # print(lower_limit, upper_limit)

if lower_limit % 10 > 0:
    lower_limit = lower_limit // 10 * 10 + 10
print(lower_limit)
0