結果

問題 No.168 ものさし
ユーザー roiti46roiti46
提出日時 2015-03-20 00:23:29
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,445 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 77,828 KB
実行使用メモリ 288,384 KB
最終ジャッジ日時 2023-08-25 20:44:58
合計ジャッジ時間 13,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 369 ms
120,840 KB
testcase_01 AC 72 ms
77,000 KB
testcase_02 AC 73 ms
76,812 KB
testcase_03 AC 73 ms
77,228 KB
testcase_04 AC 72 ms
76,760 KB
testcase_05 AC 74 ms
77,140 KB
testcase_06 AC 84 ms
79,756 KB
testcase_07 AC 75 ms
76,896 KB
testcase_08 AC 73 ms
77,020 KB
testcase_09 AC 129 ms
80,616 KB
testcase_10 AC 147 ms
81,896 KB
testcase_11 AC 316 ms
97,964 KB
testcase_12 AC 819 ms
186,172 KB
testcase_13 AC 1,229 ms
257,288 KB
testcase_14 AC 1,256 ms
271,280 KB
testcase_15 AC 85 ms
79,720 KB
testcase_16 AC 120 ms
80,704 KB
testcase_17 AC 135 ms
80,856 KB
testcase_18 AC 184 ms
86,896 KB
testcase_19 AC 1,285 ms
266,788 KB
testcase_20 AC 1,445 ms
288,384 KB
testcase_21 AC 1,399 ms
264,868 KB
testcase_22 AC 1,418 ms
281,252 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(25):
    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