結果

問題 No.134 走れ!サブロー君
ユーザー otsnskotsnsk
提出日時 2015-01-25 23:26:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,735 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 72,428 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 06:30:31
合計ジャッジ時間 1,592 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"

typedef long long ll;
typedef unsigned long long ull;

const double EPS = 1e-6;
const int d4[] = {0, -1, 0, 1, 0};

using namespace std;

struct Customer {
    int x, y;
    double w;
};

struct Node {
    int cid;
    double w, t;
};

double dist(Customer &a, Customer &b) {
    return abs(a.x-b.x) + abs(a.y-b.y);
}

const double TINF = 999999;

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

    int x0, y0, N;
    cin >> x0 >> y0 >> N;
    vector<Customer> c(N+1);
    double w0 = 0;
    FOR(i, N) {
        cin >> c[i].x >> c[i].y >> c[i].w;
        w0 += c[i].w;
    }
    c[N].x = x0; c[N].y = y0; c[N].w = 0;

    vector<Node> v(1<<N);
    int last_state = (1<<N)-1;
    FOR(i, 1<<N) v[i].t = TINF;
    v[0].w = w0; v[0].t = 0; v[0].cid = N;
    FORR(i, 1, 1<<N) {
        Node &cur = v[i];
        int b = 1;
        for (int j = 0; b <= i; b <<= 1, ++j) {
            if (i & b) {
                Node &pre = v[i^b];
                Customer &d = c[j], &s = c[pre.cid];
                double t = pre.t
                         + dist(s,d)*(pre.w+100.0)/120
                         + d.w
                         + (i==last_state? dist(d, c[N])*100/120: 0);
                if (t < cur.t) {
                    cur.t = t;
                    cur.cid = j;
                    cur.w = pre.w - d.w;
                }
            }
        }
    }

    cout << fixed << setprecision(8);
    cout << v[last_state].t << endl;

    return 0;
}
0