結果

問題 No.134 走れ!サブロー君
ユーザー assy1028assy1028
提出日時 2016-12-23 17:35:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,388 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 100,468 KB
実行使用メモリ 5,552 KB
最終ジャッジ日時 2023-08-21 07:35:43
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int x[15], y[15];
double w[15];
int wsum = 0;
int s[1<<15];
int d[15][15];

double solve() {
    n++;
    for (int i = 1; i < n; i++) wsum += w[i];
    for (int i = 0; i < 1<<n; i++) {
        int t = wsum;
        for (int j = 0; j < n; j++) {
            if ((i>>j)&1) t -= w[j];
        }
        s[i] = t;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = abs(x[i]-x[j]) + abs(y[i]-y[j]);
        }
    }
    
    double dp[1<<n][n];
    for (int i = 0; i < 1<<n; i++) fill(dp[i], dp[i]+n, inf);
    dp[1][0] = 0.0;
    for (int i = 1; i < n; i++) {
        dp[1<<i][i] = d[0][i] * ((wsum+100.0)/120.0) + w[i];
    }

    for (int i = 2; i < 1<<n; i++) {
        for (int j = 0; j < n; j++) {
            if ((i>>j)&1) {
                for (int k = 0; k < n; k++) {
                    if (k != j && (i>>k)&1) {
                        dp[i][j] = min(dp[i][j], dp[i^(1<<j)][k] + d[k][j]*((s[i^(1<<j)]+100.0)/120.0) + w[j]);
                    }
                }
            }
        }
    }
    return dp[(1<<n)-1][0];
}

void input() {
    cin >> x[0] >> y[0];
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> w[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}
0