結果

問題 No.134 走れ!サブロー君
ユーザー mamekinmamekin
提出日時 2015-02-01 02:05:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,500 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 100,292 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-22 18:03:09
合計ジャッジ時間 1,672 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 11 ms
5,504 KB
testcase_09 AC 12 ms
5,632 KB
testcase_10 AC 1 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 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int n;
vector<int> x, y;
vector<double> w;
vector<vector<double> > memo;

double solve(int curr, bitset<32> bs)
{
    if(memo[curr][bs.to_ulong()] > -0.5)
        return memo[curr][bs.to_ulong()];

    double weight = 0;
    for(int i=1; i<=n; ++i){
        if(!bs[i])
            weight += w[i];
    }
    if(weight == 0){
        int dist = abs(x[curr] - x[0]) + abs(y[curr] - y[0]);
        double t = 100.0 / 120.0 * dist;
        return t;
    }

    double ret = DBL_MAX;
    for(int i=1; i<=n; ++i){
        if(bs[i])
            continue;
        int dist = abs(x[curr] - x[i]) + abs(y[curr] - y[i]);
        double t = (weight + 100.0) / 120.0 * dist + w[i];
        bs[i] = true;
        ret = min(ret, t + solve(i, bs));
        bs[i] = false;
    }
    return memo[curr][bs.to_ulong()] = ret;
}

int main()
{
    x.resize(1);
    y.resize(1);
    cin >> x[0] >> y[0] >> n;

    x.resize(n+1);
    y.resize(n+1);
    w.resize(n+1);
    for(int i=1; i<=n; ++i)
        cin >> x[i] >> y[i] >> w[i];

    memo.assign(n+1, vector<double>(1<<(n+1), -1.0));
    printf("%.10f\n", solve(0, 0));

    return 0;
}
0