結果

問題 No.1 道のショートカット
ユーザー shimashima_kshimashima_k
提出日時 2015-04-27 10:02:43
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,360 bytes
コンパイル時間 3,349 ms
コンパイル使用メモリ 156,764 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 12:06:28
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define MAX 9999999

int main() {
    int n,c,v;
    vector<int> s,t,y,m;
    cin>>n>>c>>v;
    for (int i = 0; i < v; ++i) {
        int a;
        cin>>a;
        a--;
        s.push_back(a);
    }
    for (int i = 0; i < v; ++i) {
        int a;
        cin>>a;
        a--;
        t.push_back(a);
    }
    for (int i = 0; i < v; ++i) {
        int a;
        cin>>a;
        y.push_back(a);
    }
    for (int i = 0; i < v; ++i) {
        int a;
        cin>>a;
        m.push_back(a);
    }

    vector<vector<tuple<int,int,int> > > lib(n);
    for (int j = 0; j < v; ++j) {
        lib[s[j]].push_back(make_tuple(t[j], y[j], m[j]));
    }

    vector< vector <int> > dp(n, vector<int>(c+1, MAX));
    dp[0][c] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < c + 1; ++j) {
            if (dp[i][j] == MAX) continue;
            for (auto e: lib[i]) {
                int dest = get<0>(e);
                int cost = j - get<1>(e);
                int time = dp[i][j] + get<2>(e);
                if (time < 0) continue;
                dp[dest][cost] = min(time, dp[dest][cost]);
            }
        }
    }
    int ans = MAX;
    for (int i = 0; i < c + 1; ++i) {
        ans = min(ans, dp[n-1][i]);
    }

    if (ans == MAX) cout<<-1<<endl;
    else cout<<ans<<endl;

    return 0;
}
0