結果
| 問題 | No.5007 Steiner Space Travel | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-07-30 17:55:52 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 962 ms / 1,000 ms | 
| コード長 | 2,360 bytes | 
| コンパイル時間 | 720 ms | 
| 実行使用メモリ | 87,536 KB | 
| スコア | 5,795,032 | 
| 最終ジャッジ日時 | 2022-07-30 17:56:25 | 
| 合計ジャッジ時間 | 32,115 ms | 
| ジャッジサーバーID (参考情報) | judge12 / judge9 | 
| 純コード判定しない問題か言語 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 30 | 
ソースコード
import sys
import time
import random
from heapq import heapify, heappush, heappop
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
ALP2 = 25
LIMIT = 0.86
START = time.time()
def calc_score(root):
  ans = 0
  E = []
  for i in range(1, n):
    u, v = root[i][1]-1, root[i-1][1]-1
    tmp = (ab[u][0] - ab[v][0])*(ab[u][0] - ab[v][0]) + (ab[u][1] - ab[v][1])*(ab[u][1] - ab[v][1])
    heappush(E, (tmp, i))
    if len(E) > 8:
      heappop(E)
    ans += ALP2 * tmp
  v = root[-1][1]
  tmp = (ab[0][0] - ab[v][0])*(ab[0][0] - ab[v][0]) + (ab[0][1] - ab[v][1])*(ab[0][1] - ab[v][1])
  ans += ALP2 * tmp
  heappush(E, (tmp, n))
  if len(E) > 8:
    heappop(E)
  stations = []
  E.sort(key=lambda x: x[1])
  for c,i in E:
    if i == n:
      v = root[-1][1]-1
      stations.append(((ab[0][0] + ab[v][0])>>1, (ab[0][1] + ab[v][1])>>1))
      ans -= c * ALP2
      ans += c * ALP
    else:
      u, v = root[i][1]-1, root[i-1][1]-1
      stations.append(((ab[u][0] + ab[v][0])>>1, (ab[u][1] + ab[v][1])>>1))
      ans -= c * ALP2
      ans += c * ALP
  for i in range(8):
    if E[i][1] + i > len(root):
      root.append((E[i][1]+i, (2, i+1, 0)))
    else:
      root.insert(E[i][1]+i, (2, i+1, 0))
  return root, stations, ans
def make_stations():
  stations = []
  return stations
def make_root():
  C = [(1, i, ab[i-1]) for i in range(2, n+1)]
  c = []
  d1 = random.randint(50, 200)
  d2 = random.randint(50, 200)
  a, b = list(range(1000//d1 + 3)), list(range(1000//d2 + 3))
  i = random.randint(0, len(a))
  a = a[i:] + a[:i]
  b = b[i:] + b[:i]
  for i in a:
    b = b[::-1]
    for j in b:
      tmp = []
      for k in C:
        if d1*i <= k[2][0] <= d1*(i+1) and d2*j <= k[2][1] <= d2*(j+1):
          tmp.append(k)
      for t in tmp:
        C.remove(t)
      tmp.sort(key=lambda x: sum(x[2]))
      c.extend(tmp)
  return [(1, 1, 0)] + c
vestscore = float('inf')
st, ro = [], []
while time.time() - START < LIMIT:
  root = make_root()
  try:
    root, stations, score = calc_score(root)
    if score < vestscore:
      vestscore = score
      st = stations[:]
      ro = root[:]
  except IndexError:
    pass
for i,j in st:
  print(i, j)
print(len(ro)+1)
for i,j,_ in ro:
  print(i, j)
print(1, 1)
            
            
            
        