結果

問題 No.168 ものさし
ユーザー matsu7874matsu7874
提出日時 2015-10-04 17:44:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,502 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 29,620 KB
最終ジャッジ日時 2023-09-27 01:59:50
合計ジャッジ時間 6,573 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
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):
        while self.table[x] >= 0:
            x = self.table[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):
        for j in range(N):
            if D[i][j] <= l:
                uf.union(i, j)
    print([uf.find(i) for i in range(N)])
    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):
    for j in range(N):
        D[i][j] = distance2(P[i][0], P[i][1], P[j][0], P[j][1])

lower_limit = 0
upper_limit = int(1.5 * 10**9)
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