結果

問題 No.1 道のショートカット
ユーザー ynq1242ynq1242
提出日時 2014-10-26 14:23:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,031 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 88,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:34:57
合計ジャッジ時間 2,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
#include<ctime>
#include<set>
using namespace std;


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define F first
#define S second
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

vector<string> split(const string &str, char delim){
  istringstream iss(str); string tmp; vector<string> res;
  while(getline(iss, tmp, delim)) res.push_back(tmp);
  return res;
}

li sstoi(string s){
	return atoi(s.c_str());
}

li n,c,v;
vector<pair<li, pair<li,li> > > edge[60];

li s[1515], t[1515], y[1515], m[1515];
li dp[60][333];

int main(){
	cin>>n>>c>>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,v){
		edge[s[i]-1].pb(mp(t[i]-1, mp(y[i], m[i])));
	}

	rep(i,n)rep(j,c+1)dp[i][j]=-1;
	rep(i,c+1)dp[0][i]=0;

	rep(i,n-1){
		rep(j,c+1){
			if(dp[i][j]>=0)
			rep(k,sz(edge[i])){
				li next=edge[i][k].F;
				li cost=edge[i][k].S.F;
				li times=edge[i][k].S.S;
				if(j+cost<=c){
					if(dp[next][j+cost]<0)dp[next][j+cost]=dp[i][j]+times;
					else dp[next][j+cost]=min(dp[next][j+cost], dp[i][j]+times);
				}
			}
		}
	}

	li res=100000000;
	rep(i,c+1)if(dp[n-1][i]>=0)res=min(res, dp[n-1][i]);
	cout<<(res<100000000 ? res : -1)<<endl;


	return 0;
}
0