結果

問題 No.1 道のショートカット
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-28 19:53:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,502 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 179,292 KB
実行使用メモリ 135,288 KB
最終ジャッジ日時 2023-09-22 13:34:43
合計ジャッジ時間 8,334 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

struct Edge {
    int to,cost, time;
};

int main() {
    int n, c, v;
    cin >> n >> c >> v;
    vector<vector<Edge>> G(n);
    vector<int> s(v),t(v),y(v),m(v);
    // dp[i][j]:頂点1から頂点iにコストjで行けるときの最小の時間
    vector<vector<ll>> dp(n,vector<ll>(c+1,LLINF));
    REP(i,c) dp[0][i] = 0;
    REP(i, v) cin >> s[i];
    REP(i, v) cin >> t[i];
    REP(i, v) cin >> y[i];
    REP(i, v) cin >> m[i];
    REP(i, v) {
        G[s[i] - 1].push_back({t[i] - 1,y[i],m[i]});
    }
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int q = que.front(); que.pop();
        for (Edge e : G[q]) {
            REP(i, c - e.cost + 1) {
                if (dp[q][i] != LLINF) {
                    dp[e.to][e.cost + i] = min(dp[e.to][e.cost + i], dp[q][i] + e.time);
                }
            }
            que.push(e.to);
        }
    }
    ll ans = LLINF;
    REP(i, c + 1) {
        if (dp[n - 1][i] != LLINF) {
            ans = min(ans, dp[n - 1][i]);
        }
    }
    if (ans == LLINF) ans = -1;
    cout << ans << endl;
    getchar(); getchar();
}
0