結果

問題 No.134 走れ!サブロー君
ユーザー commycommy
提出日時 2019-03-31 00:25:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,732 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 83,340 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 18:45:08
合計ジャッジ時間 1,682 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 9 ms
5,376 KB
testcase_09 AC 8 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0