結果
問題 | No.5007 Steiner Space Travel |
ユーザー | Edomonndo365 |
提出日時 | 2023-04-25 12:27:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 307 ms / 1,000 ms |
コード長 | 2,453 bytes |
コンパイル時間 | 460 ms |
コンパイル使用メモリ | 87,180 KB |
実行使用メモリ | 81,568 KB |
スコア | 6,629,940 |
最終ジャッジ日時 | 2023-04-25 12:28:02 |
合計ジャッジ時間 | 11,689 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 291 ms
80,312 KB |
testcase_01 | AC | 290 ms
80,452 KB |
testcase_02 | AC | 296 ms
80,828 KB |
testcase_03 | AC | 295 ms
80,276 KB |
testcase_04 | AC | 290 ms
81,328 KB |
testcase_05 | AC | 289 ms
79,932 KB |
testcase_06 | AC | 294 ms
80,276 KB |
testcase_07 | AC | 292 ms
81,196 KB |
testcase_08 | AC | 293 ms
80,744 KB |
testcase_09 | AC | 293 ms
80,324 KB |
testcase_10 | AC | 290 ms
80,672 KB |
testcase_11 | AC | 291 ms
80,832 KB |
testcase_12 | AC | 307 ms
81,012 KB |
testcase_13 | AC | 291 ms
80,996 KB |
testcase_14 | AC | 291 ms
80,240 KB |
testcase_15 | AC | 294 ms
80,724 KB |
testcase_16 | AC | 293 ms
81,496 KB |
testcase_17 | AC | 291 ms
80,808 KB |
testcase_18 | AC | 290 ms
81,568 KB |
testcase_19 | AC | 291 ms
80,772 KB |
testcase_20 | AC | 296 ms
81,252 KB |
testcase_21 | AC | 292 ms
80,316 KB |
testcase_22 | AC | 289 ms
80,232 KB |
testcase_23 | AC | 290 ms
80,432 KB |
testcase_24 | AC | 291 ms
80,528 KB |
testcase_25 | AC | 291 ms
80,576 KB |
testcase_26 | AC | 289 ms
81,476 KB |
testcase_27 | AC | 291 ms
80,284 KB |
testcase_28 | AC | 292 ms
81,176 KB |
testcase_29 | AC | 288 ms
80,384 KB |
ソースコード
import sys from time import time from random import randrange START = time() INF=10**9 class Node: def __init__(self, isTerminal: bool, idx: int, pos: list): self.isTerminal = isTerminal self.idx = idx self.pos = pos self.dist = INF def __str__(self): return "{} {}".format(2-self.isTerminal, self.idx) def get_time(START): return time() - START def dist(p1,p2): x1,y1=p1 x2,y2=p2 return (x1-x2)**2 + (y1-y2)**2 def calc(idx: int): d = dist(ans[idx].pos, ans[idx+1].pos) if ans[idx].isTerminal and ans[idx+1].isTerminal: a = 25 elif ans[idx].isTerminal or ans[idx+1].isTerminal: a = 5 else: a = 1 return a * d N,M=map(int,input().split()) Terminals = [list(map(int,input().split())) for _ in range(N)] ans = [Node(True,1,Terminals[0])] candidates = set(range(1,N)) for _ in range(N-1): best_index = -1 best_dist = INF for cand in candidates: d = dist(ans[-1].pos, Terminals[cand]) if d < best_dist: best_dist = d best_index = cand assert best_index!=-1 ans.append(Node(True, best_index+1, Terminals[best_index])) candidates.discard(best_index) ans.append(Node(True,1,Terminals[0])) n = len(ans) loop_cnt1 = 0 while get_time(START) < 0.2: loop_cnt1+=1 v1 = randrange(1,n-1) v2 = randrange(1,n-1) while v1==v2: v2 = randrange(1,n-1) current_score = calc(v1-1) + calc(v1) + calc(v2-1) + calc(v2) ans[v1],ans[v2] = ans[v2],ans[v1] changed_score = calc(v1-1) + calc(v1) + calc(v2-1) + calc(v2) if changed_score < current_score: continue else: ans[v1],ans[v2] = ans[v2],ans[v1] candidates = [] for i in range(N): d = dist(ans[i].pos, ans[i+1].pos) candidates.append([i,d]) candidates.sort(key=lambda x:x[1], reverse=1) Stations = [] for i,cand in enumerate(candidates[:M], start=1): idx = cand[0] Stations.append(Node(False, i, ans[idx].pos)) for station in Stations: for i in range(len(ans)): if ans[i].pos == station.pos: ans.insert(i+1, station) break bestScore = 0 loop_cnt2 = 0 for node in Stations: print(*node.pos) print(len(ans)) for node in ans: print(node) print("Score", bestScore, file=sys.stderr) print("Loop1", loop_cnt1, file=sys.stderr) print("Loop2", loop_cnt2, file=sys.stderr) print("time:",get_time(START) * 1000, file=sys.stderr)