結果
| 問題 | No.134 走れ!サブロー君 | 
| コンテスト | |
| ユーザー |  commy | 
| 提出日時 | 2019-03-31 00:25:38 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 5,000 ms | 
| コード長 | 1,732 bytes | 
| コンパイル時間 | 710 ms | 
| コンパイル使用メモリ | 83,376 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-17 13:35:26 | 
| 合計ジャッジ時間 | 1,370 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
template<typename T>
void chmin(T &a, T b) {
    a = min(a, b);
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x, y, n;
    cin >> x >> y >> n;
    vector<int> X(n), Y(n);
    vector<double> W(n);
    double Wsum = 0;
    REP(i, 0, n) {
        cin >> X[i] >> Y[i] >> W[i];
        Wsum += W[i];
    }
    auto dp = make_v(1 << n, n, double(1e+15));
    REP(i, 0, n) {
        dp[1 << i][i] = (abs(x - X[i]) + abs(y - Y[i])) * (Wsum + 100) / 120;
    }
    REP(i, 1, 1 << n) {
        double w = 0.0;
        REP(j, 0, n) {
            if (((i >> j) & 1) == 0) {
                w += W[j];
            }
        }
        REP(j, 0, n) {
            REP(k, 0, n) {
                int nxt = i | (1 << k);
                if (i == nxt) continue;
                int dis = abs(X[j] - X[k]) + abs(Y[j] - Y[k]);
                double cost = dis * (w + 100) / 120;
                chmin(dp[nxt][k], dp[i][j] + cost);
            }
        }
    }
    double ans = 1e+15;
    REP(i, 0, n) {
        chmin(ans, dp[(1 << n) - 1][i] + (abs(x - X[i]) + abs(y - Y[i])) * 100.0 / 120);
    }
    cout << fixed << setprecision(15) << ans + Wsum << endl;
    return 0;
}
            
            
            
        