結果

問題 No.2179 Planet Traveler
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-26 19:16:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 558 ms / 3,000 ms
コード長 1,598 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 119,864 KB
最終ジャッジ日時 2023-08-20 14:00:04
合計ジャッジ時間 9,725 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,488 KB
testcase_01 AC 82 ms
71,420 KB
testcase_02 AC 83 ms
71,792 KB
testcase_03 AC 84 ms
71,464 KB
testcase_04 AC 85 ms
71,700 KB
testcase_05 AC 83 ms
71,536 KB
testcase_06 AC 84 ms
71,348 KB
testcase_07 AC 84 ms
71,892 KB
testcase_08 AC 94 ms
75,936 KB
testcase_09 AC 94 ms
76,004 KB
testcase_10 AC 96 ms
76,360 KB
testcase_11 AC 269 ms
103,160 KB
testcase_12 AC 400 ms
112,940 KB
testcase_13 AC 408 ms
113,184 KB
testcase_14 AC 251 ms
102,432 KB
testcase_15 AC 256 ms
101,748 KB
testcase_16 AC 253 ms
102,428 KB
testcase_17 AC 544 ms
119,864 KB
testcase_18 AC 445 ms
115,576 KB
testcase_19 AC 558 ms
119,120 KB
testcase_20 AC 195 ms
81,748 KB
testcase_21 AC 431 ms
111,880 KB
testcase_22 AC 335 ms
98,852 KB
testcase_23 AC 329 ms
96,544 KB
testcase_24 AC 443 ms
108,388 KB
testcase_25 AC 341 ms
99,956 KB
testcase_26 AC 486 ms
112,780 KB
testcase_27 AC 189 ms
82,156 KB
testcase_28 AC 293 ms
91,536 KB
testcase_29 AC 486 ms
110,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #




########################################
from heapq import heappush, heappop
def dijkstra( G, s, INF=10 ** 18):
    """
    https://tjkendev.github.io/procon-library/python/graph/dijkstra.html
    O((|E|+|V|)log|V|)
    V: 頂点数
    G[v] = [(nod, cost)]:
        頂点vから遷移可能な頂点(nod)とそのコスト(cost)
    s: 始点の頂点"""

    N=len(G)
    N+=1
    dist = [INF] * N
    hp = [(0, s)]  # (c, v)
    dist[s] = 0
    while hp:
        c, v = heappop(hp)  #vまで行くコストがc
        if dist[v] < c:
            continue
        for u, cost in G[v]:
            if max(dist[v] , cost) < dist[u]:
                dist[u] = max(dist[v] , cost)
                heappush(hp, (dist[u], u))
    return dist
##################################################



n=int(input())
x=[0]
y=[0]
t=[0]
for i in range(n):
    a,b,c=map(int,input().split())
    x.append(a)
    y.append(b)
    t.append(c)
def cost(i,j):
    if t[i]==t[j]:
        return (x[i]-x[j])**2+(y[i]-y[j])**2
    else:
        ri2 = x[i] ** 2 + y[i] ** 2
        rj2 = x[j] ** 2 + y[j] ** 2
        def f(s):
            if s<0:return 0
            if ri2+rj2-s<0:return 1
            return (ri2+rj2-s)**2<=4*ri2*rj2
        ng=int(abs(ri2**0.5-rj2**0.5)**2)-2
        ok=ng+4
        while ok-ng>1:
            mid=(ok+ng)//2
            if f(mid):ok=mid
            else:ng=mid
        return ok


root=[[] for i in range(n+5)]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        c=cost(i,j)
        root[i].append((j,c))
        root[j].append((i,c))

print(dijkstra(root,1)[n])




0