結果

問題 No.1 道のショートカット
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 00:48:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 945 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 53,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:36:18
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<limits>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1001001001;

int N, C, V;
int S[1500], T[1500], Y[1500], M[1500];
int dp[50][301];

int rec(int index, int cost){
    if(index == N-1){return 0;}
    if(dp[index][cost] != -1){return dp[index][cost];}

    int res = INF;
    REP(i, V){
        if(index == S[i] && cost >= Y[i]){
            res = std::min(res, rec(T[i], cost-Y[i]) + M[i]);
        }
    }

    return dp[index][cost] = res;
}

int main(){
    std::cin >> N >> C >> V;
    
    REP(i, V){std::cin >> S[i]; S[i] -= 1;}
    REP(i, V){std::cin >> T[i]; T[i] -= 1;}
    REP(i, V){std::cin >> Y[i];}
    REP(i, V){std::cin >> M[i];}

    std::fill(&dp[0][0], &dp[0][0]+50*301, -1);

    int res = rec(0, C);
    if(res == INF){
        puts("-1");
    }else{
        printf("%d\n", res);
    }
}
0