結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-13 17:42:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 1,353 bytes |
| コンパイル時間 | 1,824 ms |
| コンパイル使用メモリ | 204,724 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-07-13 17:42:33 |
| 合計ジャッジ時間 | 2,578 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
double x0,y0; cin >> x0 >> y0;
int N; cin >> N;
vector<pair<double,double>> XY(N+1);
XY.at(0) = {x0,y0};
vector<double> W(N+1);
double sumw = 0;
for(int i=1; i<=N; i++){
int x,y; double w; cin >> x >> y >> w;
XY.at(i) = {x,y},W.at(i) = w,sumw += w;
}
int n2 = 2<<N;
vector<vector<double>> dp(n2,vector<double>(N+1,1e18));
dp.at(1).at(0) = 0;
for(int i=1; i<n2; i++){
double noww = sumw;
for(int k=0; k<=N; k++) if((i&(1<<k))) noww -= W.at(k);
double time = (noww+100)/120;
for(int k=0; k<=N; k++) if(i&(1<<k)){
auto [x1,y1] = XY.at(k);
for(int l=0; l<=N; l++) if(!(i&(1<<l))){
auto [x2,y2] = XY.at(l);
double cost = (abs(x2-x1)+abs(y2-y1))*time;
dp.at(i+(1<<l)).at(l) = min(dp.at(i+(1<<l)).at(l),dp.at(i).at(k)+cost);
}
}
}
double answer = 1e18;
for(int i=0; i<=N; i++){
auto [x,y] = XY.at(i);
double time = 100.0/120;
double cost = time*(abs(x-x0)+abs(y-y0));
answer = min(answer,dp.at(n2-1).at(i)+cost);
}
answer += sumw;
cout << fixed << setprecision(20) << answer << endl;
}