結果

問題 No.5007 Steiner Space Travel
ユーザー yas_yasyuyas_yasyu
提出日時 2023-04-27 01:21:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 1,000 ms
コード長 3,418 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 85,560 KB
スコア 3,700,667
最終ジャッジ日時 2023-04-27 01:22:01
合計ジャッジ時間 11,039 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
85,016 KB
testcase_01 AC 270 ms
85,128 KB
testcase_02 AC 276 ms
85,464 KB
testcase_03 AC 260 ms
84,812 KB
testcase_04 AC 277 ms
85,480 KB
testcase_05 AC 259 ms
85,284 KB
testcase_06 AC 263 ms
85,060 KB
testcase_07 AC 284 ms
84,972 KB
testcase_08 AC 266 ms
85,340 KB
testcase_09 AC 282 ms
85,560 KB
testcase_10 AC 262 ms
85,244 KB
testcase_11 AC 269 ms
84,944 KB
testcase_12 AC 268 ms
85,416 KB
testcase_13 AC 292 ms
85,208 KB
testcase_14 AC 269 ms
84,968 KB
testcase_15 AC 274 ms
85,068 KB
testcase_16 AC 270 ms
85,248 KB
testcase_17 AC 300 ms
85,544 KB
testcase_18 AC 271 ms
85,024 KB
testcase_19 AC 262 ms
85,388 KB
testcase_20 AC 267 ms
85,096 KB
testcase_21 AC 295 ms
85,044 KB
testcase_22 AC 268 ms
85,428 KB
testcase_23 AC 272 ms
85,456 KB
testcase_24 AC 283 ms
84,972 KB
testcase_25 AC 291 ms
85,052 KB
testcase_26 AC 262 ms
85,140 KB
testcase_27 AC 263 ms
85,440 KB
testcase_28 AC 264 ms
85,300 KB
testcase_29 AC 259 ms
85,204 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) -> int:
	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(5_000):
		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:])
	for _ in range(5):
		ans.extend(station)
	random_shufle()
	ans = [planet[0]]+ans + [planet[0]]

if __name__ == "__main__":
	input_problem()

	solve()

	output_station()
	output_route()
0