結果
問題 | No.2955 Pizza Delivery Plan |
ユーザー |
![]() |
提出日時 | 2024-11-08 22:12:28 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 1,858 bytes |
コンパイル時間 | 2,792 ms |
コンパイル使用メモリ | 255,968 KB |
実行使用メモリ | 77,440 KB |
最終ジャッジ日時 | 2024-11-08 22:12:37 |
合計ジャッジ時間 | 6,489 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<pair<long long, long long>>pos(n + 1); rep(i, n)cin >> pos[i + 1].first >> pos[i + 1].second; n++; vector d(n, vector<double>(n)); rep(i, n)rep(j, n) { double dx = pos[i].first - pos[j].first; double dy = pos[i].second - pos[j].second; d[i][j] = sqrt(dx * dx + dy * dy); } vector dp(1 << n, vector(n, vector<double>(m + 1, LINF))); dp[1 << 0][0][m] = 0; rep(i, 1 << n)rep(j, n)rep(k, m + 1) { if (LINF == dp[i][j][k])continue; rep2(nj, 1, n) { if (1 & (i >> nj))continue; int ni = i + (1 << nj); if (0 != k) { int nk = k - 1; auto nval = dp[i][j][k] + d[j][nj]; chmin(dp[ni][nj][nk], nval); } { int nk = m - 1; auto nval = dp[i][j][k] + d[j][0] + d[0][nj]; chmin(dp[ni][nj][nk], nval); } } } double ans = LINF; rep(j, n)rep(k, m + 1) { auto tmp = dp[(1 << n) - 1][j][k]; tmp += d[j][0]; chmin(ans, tmp); } cout << fixed << setprecision(16) << ans << endl; return 0; }