結果

問題 No.1 道のショートカット
ユーザー motumotumotumotu
提出日時 2014-11-13 03:39:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 2,387 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 84,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 21:35:51
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define CLEAR(d) memset((d), 0, (sizeof((d))))
#define ALL(c) (c).begin(), (c).end()
#define ABS(x) ((x < 0) ? -(x) : (x))
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define SIZE(a) ((int)((a).size()))
#define MAX3(a, b, c) (max(max((a), (b)), (c)))
#define MIN3(a, b, c) (min(min((a), (b)), (c)))
#define MOD 1000000007
#define EPS 1e-5
#define PI  (acos(-1))
#define INF 10000000
//===================================================
struct edge { int to, cost, time; };
vector<edge> ed[51];
int dp[51][301];

int main()
{
    int n, c, v;
    cin >> n >> c >> v;
    vector<int> s(v), t(v), y(v), m(v);
    REP(i, v) cin >> s[i];
    REP(i, v) cin >> t[i];
    REP(i, v) cin >> y[i];
    REP(i, v) {
        cin >> m[i];
        edge e = { t[i], y[i], m[i] };
        ed[s[i]].push_back(e);
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = INF;
        }
    }
    queue<int> q;
    q.push(1);
    dp[1][0] = 0;
    while (!q.empty()) {
        int now = q.front(); q.pop();
        for (int i = 0; i < ed[now].size(); i++) {
            bool flag = false;
            for (int j = ed[now][i].cost; j <= c; j++) {
                if (dp[now][j - ed[now][i].cost] != INF) {
                    if (dp[ed[now][i].to][j] == INF || dp[ed[now][i].to][j] > dp[now][j - ed[now][i].cost] + ed[now][i].time) {
                        dp[ed[now][i].to][j] = min(dp[ed[now][i].to][j], dp[now][j - ed[now][i].cost] + ed[now][i].time);
                        flag = true;
                    }
                }
            }
            if (flag) q.push(ed[now][i].to);
        }
    }
    int ans = INT_MAX;
    for (int i = 0; i <= c; i++) {
        ans = min(ans, dp[n][i]);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}
0