結果

問題 No.5007 Steiner Space Travel
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-07-20 16:20:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 938 ms / 1,000 ms
コード長 1,278 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 144,800 KB
スコア 7,280,096
最終ジャッジ日時 2023-07-20 16:20:35
合計ジャッジ時間 26,782 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 912 ms
133,768 KB
testcase_01 AC 717 ms
133,164 KB
testcase_02 AC 745 ms
133,216 KB
testcase_03 AC 938 ms
135,400 KB
testcase_04 AC 764 ms
130,128 KB
testcase_05 AC 757 ms
135,980 KB
testcase_06 AC 732 ms
137,336 KB
testcase_07 AC 749 ms
136,860 KB
testcase_08 AC 776 ms
135,244 KB
testcase_09 AC 719 ms
128,580 KB
testcase_10 AC 754 ms
134,560 KB
testcase_11 AC 734 ms
132,852 KB
testcase_12 AC 762 ms
144,800 KB
testcase_13 AC 702 ms
129,788 KB
testcase_14 AC 725 ms
130,384 KB
testcase_15 AC 907 ms
135,460 KB
testcase_16 AC 886 ms
130,828 KB
testcase_17 AC 851 ms
131,884 KB
testcase_18 AC 773 ms
135,056 KB
testcase_19 AC 742 ms
133,200 KB
testcase_20 AC 696 ms
130,296 KB
testcase_21 AC 879 ms
133,600 KB
testcase_22 AC 737 ms
129,276 KB
testcase_23 AC 884 ms
130,024 KB
testcase_24 AC 713 ms
123,472 KB
testcase_25 AC 726 ms
129,772 KB
testcase_26 AC 845 ms
129,576 KB
testcase_27 AC 759 ms
136,596 KB
testcase_28 AC 731 ms
135,548 KB
testcase_29 AC 780 ms
132,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import randint
inf=998244353

def calc(a,b):
    return ((star[a][0]-star[b][0])**2+(star[a][1]-star[b][1])**2)*star[a][2]*star[b][2]

def sell():
    pos=0
    go={0}
    ans=[]
    ansdis=0
    while len(go)<N:
        next=-1
        dis=inf
        for i in range(N):
            if i not in go:
                if dist[pos][i][0]<dis:
                    next=i
                    dis=dist[pos][i][0]
        ans+=dist[pos][next][1]
        pos=next
        ansdis+=dis
        go.add(pos)
    ans+=dist[pos][0][1]
    return ansdis,ans+[0]

N,M=map(int,input().split())
star=[tuple(map(int,input().split()+["5"])) for i in range(N)]+[[randint(0,1000),randint(0,1000),1] for i in range(M)]
prest=[]
preans=[]
predis=inf
t=7
for _ in range(t):
	dist=[[[calc(i,j),[j]] for i in range(N+M)]for j in range(N+M)]
	for i in range(N+M):
		for j in range(N+M):
			for k in range(N+M):
				if dist[j][i][0]+dist[i][k][0]<dist[j][k][0]:
					dist[j][k]=[dist[j][i][0]+dist[i][k][0],dist[j][i][1]+dist[i][k][1]]
	ansdis,ans=sell()
	if predis>ansdis:
		predis=ansdis
		preans=ans[:]
		prest.clear()
		for i in range(M):
			prest.append(star[N+i][:2])
for i in range(M):
	print(*prest[i])
print(len(preans))
for i in preans:
	if i>=N:
		print(2,i-N+1)
	else:
		print(1,i+1)
0