結果

問題 No.134 走れ!サブロー君
ユーザー ninoinui
提出日時 2020-11-25 04:28:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,575 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 209,284 KB
最終ジャッジ日時 2025-01-16 05:35:51
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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

#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); }
template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); }
signed main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int X, Y, N;
cin >> X >> Y >> N, N++;
vector<tuple<int, int, double>> V(N);
V.at(0) = {X, Y, 0};
for (int i = 1; i < N; i++) {
int x, y;
double w;
cin >> x >> y >> w;
V.at(i) = {x, y, w};
}
vector<vector<int>> dist(N, vector<int>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
auto [a, b, c] = V.at(i);
auto [d, e, f] = V.at(j);
dist.at(i).at(j) = abs(a - d) + abs(b - e);
}
}
vector<double> weight(1 << N);
for (int bit = 0; bit < 1 << N; bit++) {
double tmp = 0;
for (int i = 0; i < N; i++) {
if (bit >> i & 1) {
auto [a, b, c] = V.at(i);
tmp += c;
}
}
weight.at(bit) = tmp;
}
vector<vector<double>> DP(1 << N, vector<double>(N, DBL_MAX));
DP.at(1).at(0) = 0;
for (int bit = 0; bit < 1 << N; bit++) {
for (int from = 0; from < N; from++) {
if (DP.at(bit).at(from) == DBL_MAX) continue;
for (int to = 0; to < N; to++) {
double cost = dist.at(from).at(to) * ((weight.at(bit) + 100) / 120);
cmin(DP.at(bit | 1 << to).at(to), DP.at(bit).at(from) + cost);
}
}
}
double ans = DP.at((1 << N) - 1).at(0);
for (auto [a, b, c] : V) ans += c;
cout << fixed << setprecision(7) << ans << "\n";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0