結果

問題 No.134 走れ!サブロー君
ユーザー whesonwheson
提出日時 2018-05-03 00:40:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,636 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 165,192 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-09-10 09:02:54
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,364 KB
testcase_01 AC 3 ms
7,512 KB
testcase_02 AC 4 ms
7,492 KB
testcase_03 AC 4 ms
7,356 KB
testcase_04 AC 4 ms
7,516 KB
testcase_05 AC 4 ms
7,432 KB
testcase_06 AC 6 ms
7,444 KB
testcase_07 AC 9 ms
7,572 KB
testcase_08 AC 14 ms
7,480 KB
testcase_09 AC 14 ms
7,624 KB
testcase_10 AC 3 ms
7,508 KB
testcase_11 AC 3 ms
7,412 KB
testcase_12 AC 4 ms
7,352 KB
testcase_13 AC 3 ms
7,360 KB
testcase_14 AC 3 ms
7,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n, x[105], y[105];
double w[105];
double dp[1 << 15][15];
double weight[1 << 15];
/**********************************************/

bool contain(int mask, int pos){
    return (mask & (1 << pos)) != 0;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> x[0] >> y[0] >> n;
    w[0] = 0.0;
    REP(i, n) cin >> x[i+1] >> y[i+1] >> w[i+1];

    for(int mask = 0; mask < (1 << (n + 1)); ++mask){
        double tmp = 0;
        for (int i = 0; i < n + 1; i++){
            if(!contain(mask, i)){
                tmp += w[i];
            }
        }
        weight[mask] = tmp;
    }
    REP(i, (1 << 15)) REP(j, 15) dp[i][j] = INF;
    dp[0][0] = 0;

    for(int mask = 0; mask < (1 << (n + 1)); mask++){
        REP(i, n+1){
            REP(p, n+1) if(!contain(mask, p)){
                double cost = (abs(x[i] - x[p]) + abs(y[i] - y[p])) * (weight[mask] + 100.0) / 120.0;
                dp[mask | (1 << p)][p] = min(dp[mask | (1 << p)][p], dp[mask][i] + cost);
            }
        }
    }

    double totalw = 0;
    REP(i, n+1) totalw += w[i];
    printf("%.9f\n" ,dp[(1 << (n+1)) - 1][0] + totalw);
}
0