結果

問題 No.1 道のショートカット
ユーザー ttakanottakano
提出日時 2017-12-03 14:33:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 979 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 144,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:11:57
合計ジャッジ時間 2,919 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int dp[52][302];
bool used[52][302];
int n,c,v;
int s[1502],t[1502],y[1502],m[1502];

int main(){
  cin>>n;
  cin>>c;
  cin>>v;
  REP(i,v)cin>>s[i];
  REP(i,v)cin>>t[i];
  REP(i,v)cin>>y[i];
  REP(i,v)cin>>m[i]; 
  REP(i,n+1)REP(j,c+1)dp[i][j]=mod;
  dp[1][c]=0;
  REP(i,n){
    REP(j,c+1){
      REP(k,v){
        if(dp[s[k]][j]==mod||s[k]!=i||j-y[k]<0)continue;
        dp[t[k]][j-y[k]]=min(dp[t[k]][j-y[k]],dp[i][j]+m[k]);
        //print(i<<" "<<j<<" "<<s[k]<<" "<<t[k]<<" "<<dp[t[k]][j-y[k]]);
      }
    }
  }
 int min_=mod;
 REP(i,c+1)min_=min(dp[n][i],min_);
 min_=min_==mod?-1:min_;
 print(min_);
}
0