結果

問題 No.1265 Balloon Survival
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-20 10:23:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,470 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 195,940 KB
最終ジャッジ日時 2023-10-17 14:30:20
合計ジャッジ時間 19,888 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,320 KB
testcase_01 AC 41 ms
53,320 KB
testcase_02 AC 41 ms
53,320 KB
testcase_03 AC 42 ms
53,320 KB
testcase_04 AC 41 ms
53,320 KB
testcase_05 AC 42 ms
53,320 KB
testcase_06 AC 42 ms
53,320 KB
testcase_07 AC 42 ms
53,320 KB
testcase_08 AC 41 ms
53,320 KB
testcase_09 AC 41 ms
53,320 KB
testcase_10 AC 41 ms
53,320 KB
testcase_11 AC 42 ms
53,320 KB
testcase_12 AC 43 ms
53,320 KB
testcase_13 AC 41 ms
53,320 KB
testcase_14 AC 236 ms
88,348 KB
testcase_15 AC 191 ms
84,292 KB
testcase_16 AC 105 ms
78,568 KB
testcase_17 AC 778 ms
132,624 KB
testcase_18 AC 136 ms
80,332 KB
testcase_19 AC 110 ms
79,000 KB
testcase_20 AC 218 ms
87,580 KB
testcase_21 AC 414 ms
101,736 KB
testcase_22 AC 279 ms
92,092 KB
testcase_23 AC 307 ms
93,648 KB
testcase_24 AC 1,470 ms
195,940 KB
testcase_25 AC 1,465 ms
195,872 KB
testcase_26 AC 1,458 ms
195,880 KB
testcase_27 AC 1,442 ms
195,464 KB
testcase_28 AC 1,449 ms
195,512 KB
testcase_29 AC 1,449 ms
195,460 KB
testcase_30 AC 1,449 ms
195,236 KB
testcase_31 AC 1,451 ms
195,404 KB
testcase_32 AC 1,443 ms
195,240 KB
testcase_33 AC 1,450 ms
195,272 KB
testcase_34 AC 49 ms
59,084 KB
testcase_35 AC 40 ms
53,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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