結果

問題 No.134 走れ!サブロー君
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-03-06 15:19:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 2,094 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 84,396 KB
実行使用メモリ 6,468 KB
最終ジャッジ日時 2023-10-19 03:41:14
合計ジャッジ時間 1,477 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

ld sx, sy;

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

ld dp[(1 << 13)][20];

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

    rep(i,0,(1 << 13) - 1)
    {
        rep(j,0,19)
        {
            dp[i][j] =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][j] = 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]);

                            dp[i][j] = min(dp[i][j], dp[sub][k] + d * (weight + 100) / 120 + w[j]);
                        }
                    }
                }
            }
        }
    }
    cout << fixed << setprecision(10);
    ld result = 1e9;
    rep(i,0,n - 1)
    {
        ld d = dist(sx,sy,x[i],y[i]) * 100 / 120;
        result = min(result , dp[(1 << n) - 1][i] + d);
    }
    cout << result << endl;
}
0