結果

問題 No.134 走れ!サブロー君
ユーザー roiti46roiti46
提出日時 2015-01-23 01:52:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,490 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 60,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 03:57:16
合計ジャッジ時間 1,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
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 <algorithm>
#include <numeric>
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,(a))
using namespace std;
const int MAX = 13;
int x, y, N;
int X[MAX], Y[MAX], W[MAX];
double d[MAX][MAX];
int dp[1 << MAX][MAX];

double cost(int S, int u, int v) {
    int sum = 0;
    rep(i,N) if (!(S >> i & 1)) sum += W[i];
    return d[u][v]*(100.0+sum)/120.0;
}

double rec(int S, int v) {
    if (dp[S][v] >= 0.0) {
        return dp[S][v];
    }
    
    if (S == (1 << N)-1) {
        return 0;
    }
    
    double res = 1 << 30;
    rep(u,N){
        if (u == v) continue;
        if (!(S >> u & 1)) {
            double tmp = rec(S|1 << u, u)+cost(S,v,u)+W[u];
            
            if ((S|1 << u) == (1 << N)-1) {
                double back = (abs(x-X[u])+abs(y-Y[u]))*100.0/120.0;
                res = min(res, tmp+back);
            }
            else {
                res = min(res, tmp);
            }
        }
    }   
    return dp[S][v] = res;
}

int main(void) {
    cin >> x >> y;
    cin >> N;
    rep(i,N) cin >> X[i] >> Y[i] >> W[i];
    
    rep(i,N) REP(j,i+1,N) d[i][j] = d[j][i] = abs(X[i]-X[j])+abs(Y[i]-Y[j]);
    double sumW = accumulate(W,W+N,0);
    
    double ans = 1 << 30;
    rep(s,N){
        rep(i,1 << MAX) rep(j,N) dp[i][j] = -1.0;

        double start = (abs(x-X[s])+abs(y-Y[s]))*(100.0+sumW)/120.0+W[s];
        ans = min(ans, rec(1 << s,s)+start);
    }
    
    printf("%.10f",ans);
    return 0;
}
0