結果

問題 No.168 ものさし
ユーザー roiti46roiti46
提出日時 2015-03-20 00:24:15
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,283 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 77,700 KB
実行使用メモリ 255,364 KB
最終ジャッジ日時 2023-08-25 20:45:17
合計ジャッジ時間 11,567 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 366 ms
120,736 KB
testcase_01 AC 74 ms
77,156 KB
testcase_02 AC 74 ms
77,128 KB
testcase_03 AC 73 ms
76,996 KB
testcase_04 AC 72 ms
76,896 KB
testcase_05 AC 73 ms
76,772 KB
testcase_06 AC 83 ms
79,696 KB
testcase_07 AC 73 ms
77,152 KB
testcase_08 AC 73 ms
76,980 KB
testcase_09 AC 127 ms
80,588 KB
testcase_10 AC 144 ms
81,864 KB
testcase_11 AC 297 ms
98,024 KB
testcase_12 AC 704 ms
162,200 KB
testcase_13 AC 1,041 ms
216,152 KB
testcase_14 AC 1,072 ms
239,444 KB
testcase_15 AC 83 ms
79,620 KB
testcase_16 AC 121 ms
80,624 KB
testcase_17 AC 135 ms
80,768 KB
testcase_18 AC 182 ms
86,964 KB
testcase_19 AC 1,138 ms
246,456 KB
testcase_20 AC 1,283 ms
255,364 KB
testcase_21 AC 1,244 ms
255,348 KB
testcase_22 AC 1,245 ms
255,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
inf = 10**12
def dist(i,j):
    x1,y1 = XY[i]
    x2,y2 = XY[j]
    d = (x1-x2)**2+(y1-y2)**2
    if d-int(d**0.5)**2 > 0:
        return int(d**0.5)/10*10+10
    else:
        if int(d**0.5)%10 == 0:
            return int(d**0.5)
        else:
            return int(d**0.5)/10*10+10

def dijkstra():
    d = [inf]*N
    used = [False]*N
    d[0] = 0
    while 1:
        v = -1
        for u in xrange(N):
            if not used[u] and (v == -1 or d[u] < d[v]): v = u
        if v == -1: break
        used[v] = True
        for u in xrange(N):
            d[u] = min(d[u], d[v]+D[v][u])
    return d[N-1]
    
N = int(raw_input())
XY = [map(int,raw_input().split()) for i in xrange(N)]
_D = [[dist(i,j) for i in xrange(N)] for j in xrange(N)]
dset = sorted(list(set([_D[i][j] for i in xrange(N) for j in xrange(N)])))
ans = max(dset)
l,p,r = 0,len(dset)/2,len(dset)
for loop in xrange(20):
    D = [[_D[i][j] if _D[i][j] <= dset[p] else inf for i in xrange(N)] for j in xrange(N)]
    if dijkstra() < inf:
        ans = min(ans,dset[p])
        r = p
    else:
        l = p
    p = (r+l)/2
print ans
0