結果
問題 | No.1265 Balloon Survival |
ユーザー |
|
提出日時 | 2021-02-20 10:23:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,308 ms / 2,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 196,892 KB |
最終ジャッジ日時 | 2024-09-17 12:17:34 |
合計ジャッジ時間 | 17,076 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
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)