結果

問題 No.168 ものさし
ユーザー nisizawanisizawa
提出日時 2017-12-19 10:04:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,023 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 141,996 KB
最終ジャッジ日時 2024-05-10 01:09:55
合計ジャッジ時間 21,222 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 531 ms
94,696 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 40 ms
52,224 KB
testcase_03 AC 40 ms
52,352 KB
testcase_04 AC 39 ms
52,096 KB
testcase_05 AC 42 ms
52,480 KB
testcase_06 AC 43 ms
52,992 KB
testcase_07 AC 40 ms
52,480 KB
testcase_08 AC 41 ms
52,736 KB
testcase_09 AC 82 ms
76,476 KB
testcase_10 AC 114 ms
77,640 KB
testcase_11 AC 440 ms
92,544 KB
testcase_12 AC 1,624 ms
129,624 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 41 ms
52,352 KB
testcase_16 AC 83 ms
76,544 KB
testcase_17 AC 103 ms
77,056 KB
testcase_18 AC 164 ms
79,660 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