結果

問題 No.134 走れ!サブロー君
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-05-22 15:42:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,661 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 167,748 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 05:55:52
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.22 15:42:00
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int x0, y0;
    cin >> x0 >> y0;
    int n;
    cin >> n;
    vector< tuple< int, int, double > > a(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        double w;
        cin >> x >> y >> w;
        a[i] = make_tuple(x, y, w);
    }
    vector< vector< double > > dp((1 << n), vector< double >(n + 1, 500000));
    vector< double > sum(1 << n, 0);
    dp[0][0] = 0;
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                sum[i] += get< 2 >(a[j]);
            }
        }
    }
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                if (i == (1 << j)) {
                    dp[i][j + 1] = dp[0][0] + (abs(x0 - get< 0 >(a[j])) + abs(y0 - get< 1 >(a[j]))) * (sum[(1 << n) - 1] + 100) / 120 + get<2>(a[j]);
                }
                for (int k = 0; k < n; k++) {
                    if ((i ^ (1 << j)) & (1 << k)) {
                        dp[i][j + 1] = min(dp[i][j + 1], dp[i ^ (1 << j)][k + 1] + (abs(get< 0 >(a[k]) - get< 0 >(a[j])) + abs(get< 1 >(a[k]) - get< 1 >(a[j]))) * (sum[(((1 << n) - 1) ^ i ^ (1 << j))] + 100) / 120 + get<2>(a[j]));
                    }
                }
            }
        }
    }
    double ans = 500000;
    for (int i = 0; i < n; i++) {
        ans = min(ans, dp[(1 << n) - 1][i + 1] + (abs(x0-get<0>(a[i]))+abs(y0-get<1>(a[i])))*10.0/12);
    }
    printf("%.10f\n", ans);
    return 0;
}
0