結果

問題 No.1 道のショートカット
ユーザー albicillaalbicilla
提出日時 2017-09-21 09:11:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 970 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 150,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:10:56
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }


using ll = long long;
const ll mod = LLONG_MAX;

VV dp;
int main(){
  int N,C,V;
  cin>>N>>C>>V;
  vector<int> S(V),T(V),Y(V),M(V);
  dp = VV(N+10,vector<int>(C+1,INF));
  rep(i,V)cin>>S[i];
  rep(i,V)cin>>T[i];
  rep(i,V)cin>>Y[i];
  rep(i,V)cin>>M[i];


  //dp[i][]=min(dp[i][],dp[i-1][]+M[i])

  //chmin(dp[i][j],dp[i-1][j-Y[k]]+M[k])

  dp[1][C]=0;

  for(int i=1;i<=N;i++){
    for(int j=C;j>=0;j--){

      for(int k=0;k<V;k++){
        if(j>=Y[k] && i==S[k])chmin(dp[T[k]][j-Y[k]],dp[S[k]][j]+M[k]);
      }
    }
  }

  int ans=*min_element(all(dp[N]));
  if(ans!=INF)cout<<ans<<endl;
  else cout<<"-1"<<endl;

}
0