結果

問題 No.2955 Pizza Delivery Plan
ユーザー t9unkubj
提出日時 2024-11-08 21:52:45
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,786 ms / 2,000 ms
コード長 2,055 bytes
コンパイル時間 3,896 ms
コンパイル使用メモリ 281,292 KB
実行使用メモリ 103,920 KB
最終ジャッジ日時 2024-11-08 21:53:34
合計ジャッジ時間 28,955 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#ifdef t9unkubj
#include"debug.cpp"
//#include"template_no_debug.h"
#else
#define dbg(...) 199958
#endif
#undef _GLIBCXX_DEBUG
#pragma GCC optimize("O3")
using namespace std;
#include<bits/stdc++.h>
using ll=long long;
using ull=unsigned long long;
template<class T>using vc=vector<T>;
template<class T>using vvc=vc<vc<T>>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)
#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)
#define drep(i,n) for(ll i=((n)-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T,class F>
bool chmin(T &x, F y){
if(x>y){
x=y;
return true;
}
return false;
}
template<class T, class F>
bool chmax(T &x, F y){
if(x<y){
x=y;
return true;
}
return false;
}
double pass_time=0;
void solve(){
using ld=long double;
int n,k;
cin>>n>>k;
vc<ll>x(n),y(n);
rep(i,n)cin>>x[i]>>y[i];
x.push_back(0);
y.push_back(0);
vc dp(1<<n,vc(k+1,vc<ld>(n+1,2e18)));
dp[0][k][n]=0;
using P=tuple<ld,int,int,int>;
priority_queue<P,vector<P>,greater<P>>que;
que.push({0,0,k,n});
while(que.size()){
auto [dis,cond,pizza,now]=que.top();que.pop();
if(dis!=dp[cond][pizza][now])continue;
rep(i,n){
if(cond>>i&1)continue;
if(pizza==0)continue;
ld nxt=dis+sqrtl((x[i]-x[now])*(x[i]-x[now])+(y[i]-y[now])*(y[i]-y[now]));
if(chmin(dp[cond+(1<<i)][pizza-1][i],nxt)){
que.push({nxt,cond+(1<<i),pizza-1,i});
}
}
if(chmin(dp[cond][k][n],dis+sqrtl(x[now]*x[now]+y[now]*y[now]))){
que.push({dp[cond][k][n],cond,k,n});
}
}
ld ans=2e18;
rep(i,k+1){
chmin(ans,dp.back()[i][n]);
}
cout<<fixed<<setprecision(20)<<ans<<endl;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
pass_time=clock();
int t=1;
//cin>>t;
while(t--)solve();
pass_time=clock()-pass_time;
dbg(pass_time/CLOCKS_PER_SEC);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0