結果

問題 No.2179 Planet Traveler
ユーザー とりゐとりゐ
提出日時 2023-01-06 22:17:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 650 ms / 3,000 ms
コード長 1,798 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 84,364 KB
最終ジャッジ日時 2023-08-20 15:28:20
合計ジャッジ時間 13,196 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
71,596 KB
testcase_01 AC 98 ms
71,492 KB
testcase_02 AC 98 ms
71,628 KB
testcase_03 AC 100 ms
71,296 KB
testcase_04 AC 96 ms
71,672 KB
testcase_05 AC 98 ms
71,664 KB
testcase_06 AC 99 ms
71,504 KB
testcase_07 AC 113 ms
77,544 KB
testcase_08 AC 138 ms
78,436 KB
testcase_09 AC 140 ms
78,004 KB
testcase_10 AC 134 ms
78,400 KB
testcase_11 AC 406 ms
83,480 KB
testcase_12 AC 561 ms
83,704 KB
testcase_13 AC 611 ms
83,800 KB
testcase_14 AC 379 ms
83,668 KB
testcase_15 AC 388 ms
83,712 KB
testcase_16 AC 386 ms
83,556 KB
testcase_17 AC 650 ms
84,092 KB
testcase_18 AC 616 ms
84,152 KB
testcase_19 AC 648 ms
84,364 KB
testcase_20 AC 238 ms
79,092 KB
testcase_21 AC 576 ms
83,956 KB
testcase_22 AC 468 ms
82,768 KB
testcase_23 AC 444 ms
82,484 KB
testcase_24 AC 527 ms
82,616 KB
testcase_25 AC 472 ms
82,452 KB
testcase_26 AC 580 ms
83,036 KB
testcase_27 AC 248 ms
79,784 KB
testcase_28 AC 387 ms
81,160 KB
testcase_29 AC 617 ms
84,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parents=[-1]*n

  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]

  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)

    if x==y:
      return

    if self.parents[x]>self.parents[y]:
      x,y=y,x

    self.parents[x]+=self.parents[y]
    self.parents[y]=x

  def size(self,x):
    return -self.parents[self.find(x)]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def members(self,x):
    root=self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x< 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    group_members=defaultdict(list)
    for member in range(self.n):
      group_members[self.find(member)].append(member)
    return group_members



n=int(input())
xyt=[]
for i in range(n):
  x,y,t=map(int,input().split())
  xyt.append((x,y,t))

dist=[[10**18]*n for i in range(n)]
def calc(a,b):
  a,b=min(a,b),max(a,b)
  #print(a,b)
  ng,ok=-1,3*10**9
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if a+b-mid<0 or (a+b-mid)**2<=4*a*b:
      ok=mid
    else:
      ng=mid
  return ok


  
for i in range(n):
  for j in range(i+1,n):
    xi,yi,ti=xyt[i]
    xj,yj,tj=xyt[j]
    if ti!=tj:
      dist[i][j]=calc(xi*xi+yi*yi,xj*xj+yj*yj)
    else:
      dx=xi-xj
      dy=yi-yj
      dist[i][j]=dx*dx+dy*dy

ng,ok=-1,10**18
while abs(ng-ok)>1:
  mid=(ng+ok)//2
  uf=UnionFind(n)
  for i in range(n):
    for j in range(i+1,n):
      if dist[i][j]<=mid:
        uf.union(i,j)
  if uf.same(0,n-1):
    ok=mid
  else:
    ng=mid
print(ok)
0