結果

問題 No.1 道のショートカット
ユーザー commycommy
提出日時 2018-08-10 23:08:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,962 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 90,336 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 13:22:04
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

struct Edge {
    lli t, y, m;
    Edge(lli _t, lli _y, lli _m)
        : t(_t), y(_y), m(_m) {}
    Edge() {}
    bool operator>(Edge const &e) const {
        return m < e.m;
    }
};

int main() {
    int N, C, V;
    cin >> N >> C >> V;
    vector<int> S(V), T(V), Y(V), M(V);
    REP(i, 0, V) {
        cin >> S[i];
    }
    REP(i, 0, V) {
        cin >> T[i];
    }
    REP(i, 0, V) {
        cin >> Y[i];
    }
    REP(i, 0, V) {
        cin >> M[i];
    }
    vector<vector<Edge>> G(N);
    REP(i, 0, N) {
        G[S[i] - 1].push_back(Edge(T[i] - 1, Y[i], M[i]));
    }
    const lli inf = 1LL << 60;
    priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
    pq.emplace(0, 0, 0);
    auto cost = make_v(N, C + 1, inf);
    auto used = make_v(N, C + 1, false);
    cost[0][0] = 0;
    lli ans = inf;
    while (pq.size()) {
        auto elem = pq.top();
        pq.pop();
        if (used[elem.t][elem.y]) continue;
        used[elem.t][elem.y] = true;
        if (elem.t == N - 1) {
            ans = min(ans, elem.m);
            continue;
        }
        for (auto &e : G[elem.t]) {
            lli ny = elem.y + e.y;
            lli nm = elem.m + e.m;
            if (ny > C) {
                continue;
            }
            if (cost[e.t][ny] > nm) {
                cost[e.t][ny] = nm;
                pq.emplace(e.t, ny, nm);
            }
        }
    }
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}
0