結果

問題 No.134 走れ!サブロー君
ユーザー veqccveqcc
提出日時 2019-02-16 16:46:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,613 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 93,520 KB
実行使用メモリ 4,688 KB
最終ジャッジ日時 2023-10-23 20:13:37
合計ジャッジ時間 1,932 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int n;
double sx, sy, x[13], y[13], w[13], dp[1 << 13][13];

double time(double weight) {
    return (weight + 100.0) / 120.0;
}

double manhattan(double x1, double x2, double y1, double y2) {
    return abs(x1 - x2) + abs(y1 - y2);
}

int main() {
    cin >> sx >> sy >> n;
    double w_sm = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> w[i];
        w_sm += w[i];
    }

    for (int i = 0; i < n; i++) {
        dp[1 << i][i] = w[i] + time(w_sm) * manhattan(sx, x[i], sy, y[i]);
    }

    for (int i = 1; i < (1 << n); i++) {
        // 今の重さ
        double weight = 0.0;
        for (int j = 0; j < n; j++) {
            if (!(i & (1 << j))) {
                weight += w[j];
            }
        }

        for (int j = 0; j < n; j++) {
            if (!(i & (1 << j))) continue;

            for (int k = 0; k < n; k++) {
                if (i & (1 << k)) continue;

                int l = i | (1 << k);
                double cost = w[k] + time(weight) * manhattan(x[j], x[k], y[j], y[k]);
                dp[l][k] = dp[l][k] ? min(dp[l][k], dp[i][j] + cost) : dp[i][j] + cost;
            }
        }
    }

    double mn = 1000000000.0;
    for (int i = 0; i < n; i++) {
        mn = min(mn, dp[(1 << n) - 1][i] + time(0.0) * manhattan(sx, x[i], sy, y[i]));
    }

    cout << mn << "\n";
    return 0;
}
0