結果

問題 No.1265 Balloon Survival
コンテスト
ユーザー persimmon-persimmon
提出日時 2021-02-20 10:23:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 897 ms / 2,000 ms
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 224 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 198,064 KB
最終ジャッジ日時 2026-04-06 06:55:28
合計ジャッジ時間 12,171 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
mat=[[] for i in range(n)]
for i in range(n):
  xi,yi=xy[i]
  for j in range(i):
    xj,yj=xy[j]
    d=(xi-xj)**2+(yi-yj)**2
    mat[i].append([d,i,j])
    mat[j].append([d,j,i])

from heapq import heappop,heappush
todo=[]
for i in range(n):
  if mat[i]:
    mat[i].sort(reverse=True)
    heappush(todo,mat[i].pop())

ans=0
seen=[0]*n
while todo:
  d,i,j=heappop(todo)
  if seen[i]==1 or seen[j]==1:
    if seen[i]==0 and mat[i]:
      heappush(todo,mat[i].pop())
    if seen[j]==0 and mat[j]:
      heappush(todo,mat[j].pop())
  elif i==0 or j==0:
    ans+=1
    seen[i]=1
    seen[j]=1
    seen[0]=0
    if seen[i]==0 and mat[i]:
      heappush(todo,mat[i].pop())
  else:
    seen[i]=1
    seen[j]=1
print(ans)

0