結果

問題 No.134 走れ!サブロー君
ユーザー minatominato
提出日時 2020-04-09 09:48:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,814 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 179,220 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-09-28 21:11:27
合計ジャッジ時間 3,255 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double dp[10000][15];

double dist(double x1, double y1, double x2, double y2) {return abs(x1-x2)+abs(y1-y2);}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    double X0,Y0; cin >> X0 >> Y0;
    int N; cin >> N;
    vector<double> X(N),Y(N),W(N);
    rep(i,N) cin >> X[i] >> Y[i] >> W[i];

    rep(mask,1<<N) rep(j,N) dp[mask][j] = 1e9;
    rep(mask,1<<N) {
        double S = 0;
        rep(i,N) {
            if (!(mask&(1<<i))) S += W[i];
        }
        if (!mask) {
            rep(i,N) {
                chmin(dp[mask+(1<<i)][i],dist(X0,Y0,X[i],Y[i])*(S+100)/120.0+W[i]); 
            }
        } else {
            rep(i,N) {
                if (mask&(1<<i)) continue;
                rep(j,N) {
                    if (mask&(1<<j)) {
                        chmin(dp[mask+(1<<i)][i],dp[mask][j]+dist(X[i],Y[i],X[j],Y[j])*(S+100)/120.0+W[i]);
                    }
                }
            }
        }
    }

    double ans = 1e9;
    rep(i,N) chmin(ans, dp[(1<<N)-1][i] + 100.0*dist(X0,Y0,X[i],Y[i])/120);

    cout << fixed << setprecision(10) << ans << ln;
}
0