結果
| 問題 | No.5007 Steiner Space Travel | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-07-30 15:07:08 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 215 ms / 1,000 ms | 
| コード長 | 1,936 bytes | 
| コンパイル時間 | 266 ms | 
| 実行使用メモリ | 83,956 KB | 
| スコア | 2,041,504 | 
| 最終ジャッジ日時 | 2022-07-30 15:07:35 | 
| 合計ジャッジ時間 | 8,302 ms | 
| ジャッジサーバーID (参考情報) | judge14 / judge15 | 
| 純コード判定しない問題か言語 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 30 | 
ソースコード
import sys
import time
import random
import math
input = lambda: sys.stdin.readline().rstrip()
#  -----------------------  #
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab_set = set(ab)
ALP = 5
START = time.time()
def calc_score(stations, root):
  ans = 0
  for i in range(1, n+m):
    u, v = root[i][1]-1, root[i-1][1]-1
    ut, vt = root[i][0], root[i-1][0]
    if ut == 1:
      if vt == 1:
        ans += ALP * ALP * math.sqrt((ab[u][0] - ab[v][0])**2 + (ab[u][1] - ab[v][1])**2)
      else:
        ans += ALP * math.sqrt((ab[u][0] - stations[v][0])**2 + (ab[u][1] - stations[v][1])**2)
    else:
      if vt == 1:
        ans += ALP * math.sqrt((stations[u][0] - ab[v][0])**2 + (stations[u][1] - ab[v][1])**2)
      else:
        ans += math.sqrt((stations[u][0] - stations[v][0])**2 + (stations[u][1] - stations[v][1])**2)
  
  v = root[-1][1]
  if root[-1][0] == 1:
    ans += ALP * ALP * math.sqrt((ab[0][0] - ab[v][0])**2 + (ab[0][1] - ab[v][1])**2)
  else:
    ans += ALP * math.sqrt((ab[0][0] - ab[v][0])**2 + (ab[0][1] - ab[v][1])**2)
  return ans
def make_stations():
  stations = set()
  while len(stations) < m:
    i, j = random.randint(0, 1000), random.randint(0, 1000)
    if (i, j) in ab_set:
      continue
    stations.add((i, j))
  return list(stations)
def make_root(stations):
  A = [(1, i, ab[i-1]) for i in range(1, n+1)]
  B = [(2, i, stations[i-1]) for i in range(1, m+1)]
  C = A[1:] + B
  if random.random() < 0.5:
    C.sort(key=lambda x: x[2][0])
  else:
    C.sort(key=lambda x: x[2][1])
  return A[:1] + C
vestscore = float('inf')
ans = []
while time.time() - START < 0.1:
  stations = make_stations()
  root = make_root(stations)
  score = calc_score(stations, root)
  if score < vestscore:
    vestscore = score
    ans = [stations[:], root[:]]
for i in ans[0]:
  print(*i)
print(len(ans[1])+1)
for i in ans[1]:
  print(i[0], i[1])
print(1, 1)
            
            
            
        