結果
| 問題 |
No.2955 Pizza Delivery Plan
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-03 11:37:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,682 bytes |
| コンパイル時間 | 1,989 ms |
| コンパイル使用メモリ | 202,384 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-03 11:37:40 |
| 合計ジャッジ時間 | 4,017 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<pair<int,int>> a(n);
for(auto &&[x, y] : a) cin >> x >> y;
vector<double> dp(1 << n, 1ll << 60);
array<double, 14> tmp;
tmp.fill(1ll << 60);
vector<array<double,14>> dp2(1 << n, tmp);
auto calc = [&](int x1, int y1, int x2, int y2){
ll dx = x2 - x1, dy = y2 - y1;
return sqrt(dx * dx + dy * dy);
};
array<array<double,15>,15> T;
for(int i = 0; i < n; i++){
auto [x1, y1] = a[i];
T[i][14] = T[14][i] = calc(0, 0, x1, y1);
for(int j = i + 1; j < n; j++){
auto [x2, y2] = a[j];
T[i][j] = T[j][i] = calc(x1, y1, x2, y2);
}
}
for(int i = 0; i < n; i++){
dp2[1 << i][i] = T[i][14];
}
for(int S = 1; S < (1 << n); S++){
int popcnt = __builtin_popcount(S);
if(popcnt <= k){
double mn = 1ll << 60;
for(int i = 0; i < n; i++){
if(~S >> i & 1) continue;
mn = min(mn, dp2[S][i] + T[i][14]);
if(popcnt < k){
for(int j = 0; j < n; j++){
if(S >> j & 1) continue;
dp2[S | (1 << j)][j] = min(dp2[S | (1 << j)][j], dp2[S][i] + T[i][j]);
}
}
}
dp[S] = mn;
}else{
for(int T = (S - 1) & S; T > 0; T = (T - 1) & S){
dp[S] = min(dp[S], dp[T] + dp[S ^ T]);
}
}
}
cout << fixed << setprecision(15) << dp.back() << '\n';
}