結果

問題 No.134 走れ!サブロー君
ユーザー momoyuumomoyuu
提出日時 2023-03-26 01:47:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,258 bytes
コンパイル時間 3,646 ms
コンパイル使用メモリ 251,764 KB
実行使用メモリ 4,720 KB
最終ジャッジ日時 2023-10-19 09:26:49
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,368 KB
testcase_08 AC 7 ms
4,720 KB
testcase_09 AC 6 ms
4,720 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    double xx,yy;
    cin>>xx>>yy;
    int n;
    cin>>n;
    vector<vector<double> >dp(1<<n,vector<double>(n,1e12));
    double all = 0;
    vector<double> x(n),y(n),w(n);
    for(int i = 0;i<n;i++) cin>>x[i]>>y[i]>>w[i];
    for(int i = 0;i<n;i++) all += w[i];
    for(int i = 0;i<n;i++){
        double dx = xx - x[i];
        double dy = yy - y[i];
        double v = (all+100.)/120.;
        dp[1<<i][i] = v * (abs(dx)+abs(dy)) + w[i];
    }

    for(int i = 1;i<1<<n;i++){
        double  sum = 0;
        for(int j = 0;j<n;j++) if(~i>>j&1) sum += w[j];
        for(int j = 0;j<n;j++) if(i>>j&1) {
            for(int k = 0;k<n;k++) if(~i>>k&1) { 
                double dx = x[j] - x[k];
                double dy = y[j] - y[k];
                double v = (sum+100.)/120.;
                dp[i|1<<k][k] = min(dp[i|1<<k][k],dp[i][j]+v*(abs(dx)+abs(dy))+w[k]);
            }
        }
    }
    
    double ans = 1e12;
    for(int i = 0;i<n;i++){
        double dx = x[i] - xx;
        double dy = y[i] - yy;
        double v = 100./120.;
        ans = min(ans,dp[(1<<n)-1][i]+v*(abs(dx)+abs(dy)));
    }
    cout<<setprecision(15)<<ans<<endl;
            
    return 0;
}
0