結果

問題 No.2179 Planet Traveler
ユーザー qibqib
提出日時 2023-01-10 01:33:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 399 ms / 3,000 ms
コード長 1,089 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 83,580 KB
最終ジャッジ日時 2023-08-23 01:33:59
合計ジャッジ時間 9,720 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,288 KB
testcase_01 AC 93 ms
71,108 KB
testcase_02 AC 93 ms
71,268 KB
testcase_03 AC 96 ms
71,696 KB
testcase_04 AC 94 ms
71,360 KB
testcase_05 AC 94 ms
71,360 KB
testcase_06 AC 93 ms
71,612 KB
testcase_07 AC 104 ms
77,264 KB
testcase_08 AC 114 ms
77,788 KB
testcase_09 AC 114 ms
77,732 KB
testcase_10 AC 113 ms
77,648 KB
testcase_11 AC 357 ms
83,580 KB
testcase_12 AC 297 ms
83,172 KB
testcase_13 AC 311 ms
83,252 KB
testcase_14 AC 227 ms
83,096 KB
testcase_15 AC 282 ms
82,996 KB
testcase_16 AC 261 ms
83,196 KB
testcase_17 AC 393 ms
83,048 KB
testcase_18 AC 399 ms
82,924 KB
testcase_19 AC 376 ms
82,832 KB
testcase_20 AC 155 ms
77,636 KB
testcase_21 AC 375 ms
82,804 KB
testcase_22 AC 272 ms
81,292 KB
testcase_23 AC 246 ms
78,068 KB
testcase_24 AC 337 ms
82,204 KB
testcase_25 AC 277 ms
81,428 KB
testcase_26 AC 336 ms
82,284 KB
testcase_27 AC 151 ms
77,288 KB
testcase_28 AC 224 ms
77,556 KB
testcase_29 AC 348 ms
82,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import math

INF = 4 * 10 ** 9

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

dist = [[0 for _ in range(n)] for _ in range(n)]
for u in range(n - 1):
  xu, yu, tu = points[u]
  for v in range(u + 1, n):
    xv, yv, tv = points[v]
    if tu == tv:
      d = (xv - xu) ** 2 + (yv - yu) ** 2
    else:
      ok = 0
      ng = INF
      target = 4 * (xu ** 2 + yu ** 2) * (xv ** 2 + yv ** 2)
      while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid * mid <= target:
          ok = mid
        else:
          ng = mid

      d = (xu ** 2 + yu ** 2) + (xv ** 2 + yv ** 2) - ok
    
    dist[u][v] = d
    dist[v][u] = d

src = 0
dst = n - 1

ng = -1
ok = INF
while abs(ok - ng) > 1:
  mid = (ok + ng) // 2
  d = [INF for _ in range(n)]
  d[src] = 0
  dq = deque([src])
  while len(dq) > 0:
    cur = dq.popleft()
    for nxt in range(n):
      if d[nxt] < INF or dist[cur][nxt] > mid:
        continue

      d[nxt] = d[cur] + 1
      dq.append(nxt)

  if d[dst] < INF:
    ok = mid
  else:
    ng = mid

print(ok)
0