結果

問題 No.5007 Steiner Space Travel
ユーザー titan23titan23
提出日時 2022-07-30 14:49:14
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 909 ms / 1,000 ms
コード長 1,535 bytes
コンパイル時間 285 ms
実行使用メモリ 87,804 KB
スコア 1,128,953
最終ジャッジ日時 2022-07-30 14:49:44
合計ジャッジ時間 30,334 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 903 ms
86,364 KB
testcase_01 AC 903 ms
86,400 KB
testcase_02 AC 903 ms
87,036 KB
testcase_03 AC 906 ms
87,008 KB
testcase_04 AC 908 ms
86,396 KB
testcase_05 AC 903 ms
87,440 KB
testcase_06 AC 906 ms
86,784 KB
testcase_07 AC 902 ms
86,640 KB
testcase_08 AC 905 ms
86,532 KB
testcase_09 AC 906 ms
86,856 KB
testcase_10 AC 905 ms
86,040 KB
testcase_11 AC 909 ms
86,340 KB
testcase_12 AC 903 ms
87,060 KB
testcase_13 AC 903 ms
85,968 KB
testcase_14 AC 904 ms
87,100 KB
testcase_15 AC 905 ms
86,144 KB
testcase_16 AC 901 ms
87,540 KB
testcase_17 AC 905 ms
86,060 KB
testcase_18 AC 904 ms
87,288 KB
testcase_19 AC 909 ms
86,476 KB
testcase_20 AC 905 ms
87,196 KB
testcase_21 AC 904 ms
86,408 KB
testcase_22 AC 903 ms
86,864 KB
testcase_23 AC 903 ms
87,352 KB
testcase_24 AC 902 ms
86,552 KB
testcase_25 AC 902 ms
87,452 KB
testcase_26 AC 905 ms
86,416 KB
testcase_27 AC 903 ms
87,804 KB
testcase_28 AC 902 ms
87,600 KB
testcase_29 AC 901 ms
86,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import time
import random
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 * (ab[u][0] - ab[v][0])**2 + (ab[u][1] - ab[v][1])**2
      else:
        ans += ALP * (ab[u][0] - stations[v][0])**2 + (ab[u][1] - stations[v][1])**2
    else:
      if vt == 1:
        ans += ALP * (stations[u][0] - ab[v][0])**2 + (stations[u][1] - ab[v][1])**2
      else:
        ans += (stations[u][0] - stations[v][0])**2 + (stations[u][1] - stations[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) for i in range(1, n+1)]
  B = [(2, i) for i in range(1, m+1)]
  C = A[1:] + B
  random.shuffle(C)
  return A[:1] + C


vestscore = 0
ans = []
while time.time() - START < 0.8:
  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)
print(1, 1)
0