結果

問題 No.134 走れ!サブロー君
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-03-06 14:47:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,067 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 84,308 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 02:38:03
合計ジャッジ時間 1,585 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 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 WA -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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++)

int sx, sy;

int n;
ld x[13], y[13], w[13];

ld dp[(1 << 13)];

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];

    fill(dp, dp + (1 << 13), 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] = 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]);
                            ld last = 0;

                            dp[i] = min(dp[i], dp[sub] + d * (weight + 100) / 120 + w[j] + last);
                        }
                    }
                    if (i == (1 << n) - 1)
                    {
                        dp[i] += dist(x[j], y[j], sx, sy) * 100 / 120;
                    }
                }

            }
        }
    }
    cout << fixed << setprecision(10);
    cout << dp[(1 << n) - 1] << endl;
}
0