結果
問題 | No.134 走れ!サブロー君 |
ユーザー |
![]() |
提出日時 | 2018-03-06 15:19:46 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 11 ms / 5,000 ms |
コード長 | 2,094 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 83,532 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-18 23:54:31 |
合計ジャッジ時間 | 1,423 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
#include <iostream>#include <iomanip>#include <string>#include <vector>#include <algorithm>#include <queue>#include <set>#include <map>#include <cmath>using namespace std;typedef long long i64;typedef long double ld;typedef pair<i64, i64> P;#define rep(i, s, e) for (int i = (s); i <= (e); i++)ld sx, sy;int n;ld x[13], y[13], w[13];ld dp[(1 << 13)][20];ld dist(ld x1, ld y1, ld x2, ld y2){return abs(x1 - x2) + abs(y1 - y2);}int main(){cin >> sx >> sy;cin >> n;rep(i, 0, n - 1) cin >> x[i] >> y[i] >> w[i];rep(i,0,(1 << 13) - 1){rep(j,0,19){dp[i][j] =1e9;}}ld w_sum = 0;rep(i, 0, n - 1) w_sum += w[i];rep(i, 1, (1 << n) - 1){if (__builtin_popcount(i) == 1){rep(j, 0, n - 1){if (i & (1 << j)){dp[i][j] = dist(x[j], y[j], sx, sy) * (w_sum + 100) / 120 + w[j];break;}}}else{rep(j, 0, n - 1){if (i & (1 << j)){ld weight = 0;int sub = i & ~(1 << j);rep(k, 0, n - 1){if (!(sub & (1 << k))){weight += w[k];}}rep(k, 0, n - 1){if ((sub & (1 << k))){ld d = dist(x[j], y[j], x[k], y[k]);dp[i][j] = min(dp[i][j], dp[sub][k] + d * (weight + 100) / 120 + w[j]);}}}}}}cout << fixed << setprecision(10);ld result = 1e9;rep(i,0,n - 1){ld d = dist(sx,sy,x[i],y[i]) * 100 / 120;result = min(result , dp[(1 << n) - 1][i] + d);}cout << result << endl;}