結果

問題 No.2955 Pizza Delivery Plan
ユーザー hirayuu_yc
提出日時 2024-11-08 22:05:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 651 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 87,552 KB
最終ジャッジ日時 2024-11-08 22:05:33
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def dist(p, q):
    x1, y1 = p
    x2, y2 = q
    return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
from functools import lru_cache
@lru_cache
def calc(pizza,pos,bits):
	if pizza==0:
		return calc(K,0,bits)+dist(dot[0],dot[pos])
	if bits==((1<<(N+1))-1):
		return dist(dot[0],dot[pos])
	ret=None
	if pizza!=K:
		ret=calc(K,0,bits)+dist(dot[0],dot[pos])
	for i in range(1,N+1):
		if not (bits>>i)&1:
			now=calc(pizza-1,i,bits|(1<<i))+dist(dot[i],dot[pos])
			if ret is None:
				ret=now
			ret=min(ret,now)
	return ret
	
N,K=map(int,input().split())
dot=[(0.0,0.0)]+[tuple(map(float,input().split())) for i in range(N)]
print(calc(K,0,1))
0