結果
問題 | No.2955 Pizza Delivery Plan |
ユーザー |
|
提出日時 | 2024-11-10 14:56:48 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 1,444 bytes |
コンパイル時間 | 2,449 ms |
コンパイル使用メモリ | 207,372 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-11-10 14:56:53 |
合計ジャッジ時間 | 4,145 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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);};for(int i = 0; i < n; i++){dp2[1 << i][i] = calc(0, 0, a[i].first, a[i].second);}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] + calc(0, 0, a[i].first, a[i].second));if(popcnt < k){for(int j = 0; j < n; j++){dp2[S | (1 << j)][j] = min(dp2[S | (1 << j)][j], dp2[S][i] + calc(a[i].first, a[i].second, a[j].first, a[j].second));}}}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';}