結果

問題 No.134 走れ!サブロー君
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-24 05:00:22
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 1,252 bytes
コンパイル時間 1,312 ms
コンパイル使用メモリ 144,752 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-04-29 04:48:23
合計ジャッジ時間 2,366 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 4 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 13 ms
5,632 KB
testcase_08 AC 27 ms
7,936 KB
testcase_09 AC 27 ms
7,936 KB
testcase_10 AC 2 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 <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

int main(){

    long long N, mx;
    long double ix, iy, S=0, tot, ans=1e18;
    cin >> ix >> iy >> N;
    mx = 1<<(N+1);
    vector<long double> X(N+1), Y(N+1), W(N+1), M(mx);
    auto d = [&](int i, int j, int S){return ((M[S]+100.0)/120.0)*(abs(X[i]-X[j])+abs(Y[i]-Y[j]))+W[j];};

    X[0] = ix; Y[0] = iy;
    for (int i=1; i<=N; i++){
        cin >> X[i] >> Y[i] >> W[i];
        S += W[i];
    }
    for (int i=0; i<mx; i++){
        tot = 0;
        for (int j=0; j<N+1; j++){
            if (i & (1<<j)) tot += W[j];
        }
        M[i] = S-tot;
    }

    vector<vector<long double>> dp(mx, vector<long double>(N+1, 1e18));
    dp[1][0] = 0;

    for (int i=1; i<mx; i++){
        for (int j=0; j<N+1; j++){
            for (int k=1; k<N+1; k++){
                if (!(i & 1<<k)) dp[i|1<<k][k] = min(dp[i|1<<k][k], dp[i][j]+d(j, k, i));
            }
        }
    }

    for (int i=1; i<N+1; i++){
        ans = min(ans, dp[mx-1][i]+d(i, 0, mx-1));
    }

    cout << setprecision(18) << ans << endl;

    return 0;
}
0