結果

問題 No.168 ものさし
ユーザー nisizawanisizawa
提出日時 2017-12-19 10:04:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,023 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 147,148 KB
最終ジャッジ日時 2023-08-22 19:27:48
合計ジャッジ時間 11,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 589 ms
93,392 KB
testcase_01 AC 72 ms
71,464 KB
testcase_02 AC 72 ms
71,608 KB
testcase_03 AC 74 ms
71,548 KB
testcase_04 AC 72 ms
71,644 KB
testcase_05 AC 76 ms
71,240 KB
testcase_06 AC 75 ms
71,560 KB
testcase_07 AC 73 ms
71,352 KB
testcase_08 AC 74 ms
71,544 KB
testcase_09 AC 110 ms
77,728 KB
testcase_10 AC 144 ms
78,548 KB
testcase_11 AC 490 ms
92,708 KB
testcase_12 AC 1,718 ms
129,812 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 77 ms
71,772 KB
testcase_16 AC 118 ms
77,492 KB
testcase_17 AC 139 ms
78,088 KB
testcase_18 AC 196 ms
80,528 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def sq_dist(xy1, xy2):
    x1, y1 = xy1
    x2, y2 = xy2
    return (x2 - x1)**2 + (y2 - y1)**2

sq_dist_ls = [(sq_dist(xy_ls[i], xy_ls[j]), i, j) for i in range(n - 1) for j in range(i + 1, n)]
sq_dist_ls.sort()

low = sq_dist_ls[0][0]
high = sq_dist_ls[-1][0]

def p_find(memo, p):
    while memo[p] >= 0:
        p = memo[p]
    return p

def p_union(memo, p1, p2):
    p1_root = p_find(memo, p1)
    p2_root = p_find(memo, p2)
    if p1_root != p2_root:
        memo[p1_root] = p2_root

def get_ans(sq_x):
    x = int(sq_x**0.5 // 10 * 10)
    return x + 10 if x**2 < sq_x else x

start = 0
goal = n - 1

while get_ans(low) != get_ans(high):
    mid = (high + low) // 2
    memo = [-1] * n
    for sq_dist, p1, p2 in sq_dist_ls:
        if mid < sq_dist:
            break
        p_union(memo, p1, p2)
        
    if p_find(memo, start) == p_find(memo, goal):
        high = mid
    else:
        low = mid

ans = get_ans(high)
print(ans)
0