結果

問題 No.2955 Pizza Delivery Plan
ユーザー timi
提出日時 2024-11-08 23:04:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 868 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,248 KB
実行使用メモリ 190,828 KB
最終ジャッジ日時 2024-11-08 23:05:36
合計ジャッジ時間 20,314 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int, input().split())

D=[[-1]*(N+1) for i in range(N+1)]

A=[(0,0)]
for i in range(N):
  x,y=map(int, input().split())
  A.append((x,y))
  
for i in range(N+1):
  for j in range(N+1):
    x=A[i][0]-A[j][0]
    y=A[i][1]-A[j][1]
    D[i][j]=(x**2+y**2)**.5

cc=(N+1)*(N+1)
dp=[[10**20]*(1<<N) for i in range(cc)]
from collections import deque
d=deque()
d.append((K*(N+1),0))
dp[K*(N+1)][0]=0
while d:
  cc,bit=d.popleft()
  c,now=cc//(N+1),cc%(N+1)
  for i in range(N):
    if not (bit & (1<<i)):
      bbit=bit^(1<<i)
      cp=(c-1)*(N+1)+(i+1)
      if dp[cp][bbit]>dp[cc][bit]+D[now][i+1] and c>1:
        dp[cp][bbit]=dp[cc][bit]+D[now][i+1]
        d.append((cp,bbit))
      cp=K*(N+1)
      if dp[cp][bbit]>dp[cc][bit]+D[now][i+1]+D[i+1][0]:
        dp[cp][bbit]=dp[cc][bit]+D[now][i+1]+D[i+1][0]
        d.append((cp,bbit))
      
print(dp[K*(N+1)][-1])
0