結果

問題 No.1 道のショートカット
ユーザー fantasiabaeticafantasiabaetica
提出日時 2018-07-06 18:13:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,942 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 68,792 KB
実行使用メモリ 470,260 KB
最終ジャッジ日時 2023-09-22 13:21:19
合計ジャッジ時間 7,387 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <climits>
#include <queue>
#include <vector>
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define p_int pair<int, int>
using namespace std;

int main(){
    // 街の数、コスト上限、道の数
    int city_n, c_max, load_n;
    cin >> city_n >> c_max >> load_n;
    // 始点、終点、コスト、時間
    int s[load_n], t[load_n], c[load_n], time[load_n];
    // sから行ける場所のvector
    vector<p_int> st[city_n + 1];
    REP(i, 0, load_n) cin >> s[i];
    REP(i, 0, load_n) cin >> t[i];
    REP(i, 0, load_n) st[s[i]].push_back(make_pair(t[i], i));
    REP(i, 0, load_n) cin >> c[i];
    REP(i, 0, load_n) cin >> time[i];

    // 使った費用を縦軸、現在地を横軸に取ってDP
    int dp[c_max + 1][city_n + 1];
    REP(i, 0, c_max + 1){
        REP(j, 0, city_n + 1){
            dp[i][j] = INT_MAX;
        }
    }
    dp[0][1] = 0;
    queue<p_int> q;
    q.push(make_pair(0, 1));
    while (!(q.empty())){
        // queueの先頭の要素を取り出し、そこから行ける都市を調べる
        p_int front = q.front();
        q.pop();
        int c_front = front.first;
        int s_front = front.second;
        vector<p_int> t_goto = st[s_front];
        REP(i, 0, t_goto.size()){
            p_int t_i = t_goto[i];
            int c_next = c_front + c[t_i.second];
            if (c_next <= c_max) {
                int t_next = t_i.first;
                int time_next = dp[c_front][s_front] + time[t_i.second];
                dp[c_next][t_next] = min(dp[c_next][t_next], time_next);
                //pushする内容がおかしい
                q.push(make_pair(c_next, t_next));
            }
        }
    }

    // dp[i][city_n]における最小値を返す
    int ans = INT_MAX;
    REP(i, 0, c_max + 1){
        ans = min(ans, dp[i][city_n]);
    }
    if (ans == INT_MAX) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}
0