結果

問題 No.2179 Planet Traveler
ユーザー HydruHydru
提出日時 2023-01-06 23:47:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 111,592 KB
最終ジャッジ日時 2024-05-07 23:48:35
合計ジャッジ時間 5,838 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
61,264 KB
testcase_01 AC 39 ms
55,272 KB
testcase_02 AC 40 ms
55,036 KB
testcase_03 AC 40 ms
55,152 KB
testcase_04 AC 40 ms
54,664 KB
testcase_05 AC 40 ms
55,508 KB
testcase_06 AC 40 ms
54,260 KB
testcase_07 WA -
testcase_08 AC 66 ms
75,776 KB
testcase_09 AC 66 ms
75,972 KB
testcase_10 AC 58 ms
75,748 KB
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt
from collections import deque

n=int(input())
Z=[list(map(int,input().split())) for _ in range(n)]

G=[[0 for _ in range(n)] for _ in range(n)]
dist=[0]
dist_set=set([0])

def max_sqrt(a):
    l=1
    r=a+1
    while(r-l>1):
        mid=(r+l)//2
        if(mid**2<=a):
            l=mid
        else:
            r=mid
    return l
    


for i in range(n-1):
    for j in range(i+1,n):
        if i==j:
            continue
        if Z[i][2]==Z[j][2]:
            d=(Z[i][0]-Z[j][0])**2+(Z[i][1]-Z[j][1])**2
        else:
            d1=Z[i][0]**2+Z[i][1]**2
            d2=Z[j][0]**2+Z[j][1]**2
            d=d1+d2-2*max_sqrt(d1*d2)

        G[i][j]=d
        G[j][i]=d
        if d not in dist_set:
            dist.append(d)
            dist_set.add(d)

def dfs(G,d):
    not_visit=set([i for i in range(1,n)])
    Q=deque()
    Q.append(0)
    while(Q):
        v=Q.pop()
        visit=set()
        for i in not_visit:
            if G[v][i]<=d:
                visit.add(i)
                Q.append(i)
                if i==n-1:
                    return True
        not_visit-=visit
    return False

dist.sort()
l=-1
r=len(dist)-1
while(r-l>1):
    mid=(r+l)//2
    if(dfs(G,dist[mid])):
        r=mid
    else:
        l=mid


print(dist[r])
0