結果
問題 | No.5007 Steiner Space Travel |
ユーザー | titan23 |
提出日時 | 2022-07-30 15:24:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 906 ms / 1,000 ms |
コード長 | 2,165 bytes |
コンパイル時間 | 302 ms |
実行使用メモリ | 86,852 KB |
スコア | 3,521,672 |
最終ジャッジ日時 | 2022-07-30 15:24:38 |
合計ジャッジ時間 | 30,317 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 902 ms
85,536 KB |
testcase_01 | AC | 901 ms
86,052 KB |
testcase_02 | AC | 900 ms
86,036 KB |
testcase_03 | AC | 903 ms
86,144 KB |
testcase_04 | AC | 898 ms
85,504 KB |
testcase_05 | AC | 900 ms
85,908 KB |
testcase_06 | AC | 899 ms
86,004 KB |
testcase_07 | AC | 899 ms
85,988 KB |
testcase_08 | AC | 900 ms
85,416 KB |
testcase_09 | AC | 904 ms
86,208 KB |
testcase_10 | AC | 900 ms
84,844 KB |
testcase_11 | AC | 901 ms
85,944 KB |
testcase_12 | AC | 902 ms
85,848 KB |
testcase_13 | AC | 900 ms
86,140 KB |
testcase_14 | AC | 901 ms
85,704 KB |
testcase_15 | AC | 898 ms
86,160 KB |
testcase_16 | AC | 901 ms
86,384 KB |
testcase_17 | AC | 901 ms
85,596 KB |
testcase_18 | AC | 902 ms
85,296 KB |
testcase_19 | AC | 902 ms
85,852 KB |
testcase_20 | AC | 903 ms
85,396 KB |
testcase_21 | AC | 899 ms
86,064 KB |
testcase_22 | AC | 902 ms
85,140 KB |
testcase_23 | AC | 900 ms
85,956 KB |
testcase_24 | AC | 906 ms
85,252 KB |
testcase_25 | AC | 897 ms
85,992 KB |
testcase_26 | AC | 899 ms
85,624 KB |
testcase_27 | AC | 898 ms
86,852 KB |
testcase_28 | AC | 902 ms
85,572 KB |
testcase_29 | AC | 899 ms
85,592 KB |
ソースコード
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 LIMIT = 0.8 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 c = [] d = random.randint(50, 600) for i in range(1000//d+2): for j in range(1000//d+2): tmp = [] for k in C: if d*i <= k[2][0] <= d*(i+1) and d*j <= k[2][1] <= d*(j+1): tmp.append(k) for t in tmp: C.remove(t) tmp.sort(key=lambda x: x[2]) c.extend(tmp) return A[:1] + c vestscore = float('inf') ans = [] while time.time() - START < LIMIT: 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)