結果

問題 No.1 道のショートカット
ユーザー IL_mstaIL_msta
提出日時 2015-05-30 14:06:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,758 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 65,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 21:44:25
合計ジャッジ時間 1,801 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <string>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int N;//町の数[1,50]
int C;//手持ちのお金 所持
int E;//道の数
const int maxN = 50;
const int maxE = 1500;
int s[maxE];//sから
int t[maxE];//tへ
int y[maxE];//コスト 料金
int m[maxE];//時間

int rE[maxN+1][maxN+1];//[s][t]
/////
const int dpINF = (49*1000)*1000;
int dp[maxN+1][301];//dp[現在位置][所持金] = Nまでの時間コスト の最小値

//Nにいけなければ -1
//Nにいければ 時間コストの最小値
int solve(int from,int cost){
	if( cost > C ){
		return -1;
	}
	if( from == N){
		return 0;
	}
	if( dp[from][cost] != dpINF){
		return dp[from][cost];
	}
	
	int ans = -1;
	int ansTemp = -1;

	for(int i = 0; i < E; ++i){//1500
		if(s[i] == from){
			ansTemp = solve( t[i], cost + y[i] );//next->Nまでのコスト
			if(ansTemp != -1 ){//たどり着けた
				ansTemp += m[i];//from->nextのコストを足す
				if( ans == -1 || ans > ansTemp){
					ans = ansTemp;
				}
			}
		}
	}

	dp[from][cost] = ans;
	return ans;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;//
	//cout << setprecision(7);//
	
	cin >> N;
	cin >> C;
	cin >> E;
	
	rep(i,E)cin>>s[i];//1からN-1
	rep(i,E)cin>>t[i];//2からN
	rep(i,E)cin>>y[i];//[1,C]円
	rep(i,E)cin>>m[i];//[1,1000]時間


	//250 [0,50] [0,50] 初期化
	rep(i,maxN+1){
		rep(j,maxN+1){
			rE[i][j] = -1;
		}
	}
	
	//[0,50][0,300] 15k+300+50+1 初期化
	rep(i,maxN+1)rep(j,301)dp[i][j] = dpINF;//
	
	P(solve(1,0));

	return 0;
}
0