結果

問題 No.5007 Steiner Space Travel
ユーザー yas_yasyuyas_yasyu
提出日時 2023-04-27 01:02:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 1,000 ms
コード長 3,495 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 87,668 KB
スコア 1,215,849
最終ジャッジ日時 2023-04-27 01:02:48
合計ジャッジ時間 11,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 229 ms
87,312 KB
testcase_01 AC 232 ms
87,356 KB
testcase_02 AC 233 ms
87,448 KB
testcase_03 AC 234 ms
87,176 KB
testcase_04 AC 230 ms
87,164 KB
testcase_05 AC 231 ms
87,288 KB
testcase_06 AC 233 ms
87,352 KB
testcase_07 AC 228 ms
87,128 KB
testcase_08 AC 229 ms
87,372 KB
testcase_09 AC 227 ms
87,292 KB
testcase_10 AC 227 ms
87,420 KB
testcase_11 AC 225 ms
87,260 KB
testcase_12 AC 242 ms
87,288 KB
testcase_13 AC 226 ms
87,356 KB
testcase_14 AC 258 ms
87,236 KB
testcase_15 AC 228 ms
87,332 KB
testcase_16 AC 239 ms
87,260 KB
testcase_17 AC 238 ms
87,468 KB
testcase_18 AC 232 ms
87,292 KB
testcase_19 AC 231 ms
87,356 KB
testcase_20 AC 233 ms
87,548 KB
testcase_21 AC 237 ms
87,548 KB
testcase_22 AC 231 ms
87,368 KB
testcase_23 AC 230 ms
87,668 KB
testcase_24 AC 228 ms
85,068 KB
testcase_25 AC 231 ms
87,352 KB
testcase_26 AC 229 ms
87,296 KB
testcase_27 AC 230 ms
84,776 KB
testcase_28 AC 228 ms
87,168 KB
testcase_29 AC 232 ms
87,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
import typing
TIME_LIMIT = 0.9
INF = 10**9
class Planet:
	def __init__(self, a, b, idx, is_station = False, frm = -1, nxt = -1) -> None:
		self.x = a
		self.y = b
		self.idx = idx
		self.is_station = is_station
		self.frm = frm
		self.nxt = nxt
	def copy(self):
		return Planet(self.x, self.y, self.idx, self.is_station, self.frm, self.nxt)
	
	def __str__(self) -> str:
		return " ".join(["1" if not self.is_station else "2", str(self.idx + 1)])

N:int = 100
M:int = 8
planet:typing.List[Planet] = []
station:typing.List[Planet] = []

A = 5

ans:typing.List[Planet] = []

def input_problem():
	global N, M, planet
	N, M = map(int,input().split())
	for i in range(N):
		a, b = map(int,input().split())
		planet.append(Planet(a, b, i))

def output_station():
	for s in station:
		print(s.x, s.y)

def output_route():
	print(len(ans))
	for v in ans:
		print(v)

def station_init():
	global station
	station.append(Planet(250, 250, 0, True))
	station.append(Planet(250, 500, 1, True))
	station.append(Planet(250, 750, 2, True))
	station.append(Planet(500, 250, 3, True))
	station.append(Planet(500, 750, 4, True))
	station.append(Planet(750, 250, 5, True))
	station.append(Planet(750, 500, 6, True))
	station.append(Planet(750, 750, 7, True))

def Dist(planet_A:Planet, planet_B:Planet, station_cnt:int = -1):
	if station_cnt == -1:
		station_cnt = 1 if planet_A.is_station else 0 + 1 if planet_B.is_station else 0

	dist:int = (
		(planet_A.x-planet_B.x)**2 + (planet_A.y - planet_B.y)**2
		)*(A**(2-station_cnt))
	return dist

def calc_distance() -> typing.List[typing.List[int]]:
	distance:typing.List[typing.List[int]] = [[INF]*(N+M) for _ in range(N+M)]
	for i in range(N+M):
		for j in range(N+M):
			station_cnt = 0
			if i == j:
				distance[i][j] = 0
			planet_A:Planet
			planet_B:Planet
			if i >= N:
				planet_A = station[i - N]
				station_cnt += 1
			else:
				planet_A = planet[i]

			if j >= N:
				planet_B = station[j - N]
				station_cnt += 1
			else:
				planet_B = planet[j]

			distance[i][j] = Dist(planet_A, planet_B, station_cnt)
	return distance


def FloydWarshall(d:typing.List[typing.List[int]]) -> typing.List[typing.List[int]]:
    """破壊的処理"""
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] == INF or d[k][j] == INF:
                    continue
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # if any(d[i][i] < 0 for i in range(n)): # 負の閉路があるなら0を返す.
    #     return 0
    return d

def dijkstra():
	dikstra:int

def calc_score() -> int:
	score:int = 0
	frm_planet = planet[0]
	for to_planet in ans:
		score += Dist(frm_planet, to_planet)
		frm_planet = to_planet.copy()

	return score

def random_shufle():
	global ans
	best_score = calc_score()
	for _ in range(2_500):
		a:int = 0
		b:int = 0
		while a != b:
			a = random.randrange(0, len(ans))
			b = random.randrange(0, len(ans))

		ans[a], ans[b] = ans[b], ans[a]
		now_score = calc_score()
		if now_score >= best_score:
			ans[a], ans[b] = ans[b], ans[a]
		else:
			best_score = now_score

def solve():
	global ans
	station_init()
	# distance = FloydWarshall(calc_distance())
	ans.extend(planet[1:])
	ans.extend(station)
	ans.extend(station)
	ans.extend(station)
	ans.extend(station)
	ans.extend(station)
	ans.extend(station)
	random_shufle()
	ans = [planet[0]]+ans + [planet[0]]

if __name__ == "__main__":
	input_problem()

	solve()

	output_station()
	output_route()
0