結果

問題 No.1 道のショートカット
ユーザー latte0119latte0119
提出日時 2015-10-31 18:31:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,221 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 65,484 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:48:45
合計ジャッジ時間 2,006 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 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,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 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,376 KB
testcase_27 AC 3 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 2 ms
4,380 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 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cassert>
#include<cstring>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

struct edge{
    int to,cost,t;
    edge(int to,int cost,int t):to(to),cost(cost),t(t){}
};

int N,C,M;
vector<edge>G[50];

int X[1500],Y[1500],Z[1500],W[1500];
const int INF=1001001001;
int dp[50][301];
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin>>N>>C>>M;
    rep(i,M)cin>>X[i];
    rep(i,M)cin>>Y[i];
    rep(i,M)cin>>Z[i];
    rep(i,M)cin>>W[i];

    rep(i,M){
        G[--X[i]].pb(edge(--Y[i],Z[i],W[i]));
    }

    fill_n(*dp,50*301,INF);
    dp[0][0]=0;
    rep(i,N){
        rep(j,C+1){
            rep(k,G[i].size()){
                edge &e=G[i][k];
                if(j+e.cost>C)continue;
                chmin(dp[e.to][j+e.cost],dp[i][j]+e.t);
            }
        }
    }

    int ans=*min_element(dp[N-1],dp[N-1]+C+1);
    if(ans==INF)cout<<"-1"<<endl;
    else cout<<ans<<endl;
    return 0;
}
0