結果

問題 No.168 ものさし
ユーザー tnodinotnodino
提出日時 2022-07-24 13:12:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 768 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 271,152 KB
最終ジャッジ日時 2023-09-20 12:07:24
合計ジャッジ時間 6,777 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
80,164 KB
testcase_01 AC 101 ms
71,648 KB
testcase_02 AC 94 ms
71,252 KB
testcase_03 AC 95 ms
71,648 KB
testcase_04 AC 96 ms
71,416 KB
testcase_05 AC 96 ms
71,724 KB
testcase_06 AC 103 ms
76,688 KB
testcase_07 AC 97 ms
71,388 KB
testcase_08 AC 97 ms
71,668 KB
testcase_09 AC 130 ms
77,272 KB
testcase_10 AC 139 ms
77,748 KB
testcase_11 AC 226 ms
92,152 KB
testcase_12 AC 537 ms
198,952 KB
testcase_13 AC 768 ms
271,012 KB
testcase_14 AC 750 ms
271,152 KB
testcase_15 AC 97 ms
71,252 KB
testcase_16 AC 126 ms
77,472 KB
testcase_17 AC 131 ms
77,216 KB
testcase_18 AC 140 ms
78,204 KB
testcase_19 AC 325 ms
106,460 KB
testcase_20 AC 330 ms
111,208 KB
testcase_21 AC 341 ms
111,140 KB
testcase_22 AC 340 ms
111,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def check(x):
    G = [[] for _ in range(N)]
    for i in range(N):
        for j in range(i+1,N):
            d = (X[i]-X[j])**2 + (Y[i]-Y[j])**2
            if d <= x:
                G[i].append(j)
                G[j].append(i)
    flg = [False] * N
    flg[0] = True
    Queue = deque()
    Queue.append(0)
    while Queue:
        pos = Queue.popleft()
        for nxt in G[pos]:
            if flg[nxt]:
                continue
            flg[nxt] = True
            Queue.append(nxt)
    return flg[-1]

N = int(input())
Z = [list(map(int,input().split())) for _ in range(N)]
X,Y = [list(i) for i in zip(*Z)]
ng = 0
ok = 1<<32
while ok - ng > 1:
    x = (ok+ng) // 2
    if check(x**2):
        ok = x
    else:
        ng = x
ok = (ok + 9) // 10 * 10
print(ok)
0