結果

問題 No.1 道のショートカット
ユーザー mizunomidorimizunomidori
提出日時 2016-07-01 02:13:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,760 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 78,308 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:57:16
合計ジャッジ時間 1,897 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

#define MAX_N 50
#define MAX_C 300
#define MAX_V 1500

using namespace std;

struct edge
{
    int to;
    int cost;
    int time;
};


int main(void)
{
    int n, c, v, s[MAX_V], t[MAX_V], y[MAX_V], m[MAX_V];
    cin >> n >> c >> v;
    vector<edge> g[MAX_N + 1];
    for (int i = 0; i < v; i++)
        cin >> s[i];
    for (int i = 0; i < v; i++)
        cin >> t[i];
    for (int i = 0; i < v; i++)
        cin >> y[i];
    for (int i = 0; i < v; i++)
        cin >> m[i];
    for (int i = 0; i < v; i++) {
        edge e;
        e.to = t[i]; e.cost = y[i]; e.time = m[i];
        g[s[i]].push_back(e);
    }
    int dp[MAX_N + 1][MAX_C + 1];
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = -1;
        }
    }
    dp[1][c] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            if (dp[i][j] != -1) {
                for (int k = 0; k < g[i].size(); k++) {
                    edge e = g[i][k];
                    if (e.cost <= j && (dp[e.to][j - e.cost] == -1 || dp[e.to][j - e.cost] > dp[i][j] + e.time)) {
                        dp[e.to][j - e.cost] = dp[i][j] + e.time;
                    }
                }
            }
        }
    }
    int ret = INT_MAX;
    for (int i = 0; i <= c; i++) {
        if (dp[n][i] != -1) {
            ret = min(ret, dp[n][i]);
        }
    }
    if (ret == INT_MAX) {
        ret = -1;
    }
    printf("%d\n", ret);
    return 0;
}
0