結果

問題 No.1 道のショートカット
ユーザー IL_mstaIL_msta
提出日時 2015-05-30 11:21:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,993 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 65,180 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 12:16:08
合計ジャッジ時間 2,235 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,376 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 maxE = 1500;
int s[maxE];//sから
int t[maxE];//tへ
int y[maxE];//コスト 料金
int m[maxE];//時間

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

int solve(int from,int c){
	//cout << "[slove]" << from << " " << c << endl;
	if( c < 0){
		return -1;
	}
	if( from == N){
		return 0;
	}
	if( dp[from][c] != dpINF){
		return dp[from][c];
	}
	///////////
	int ans = -1;
	int ansTemp = -1;
	int eNum;

	for(int i=from+1; i<=N; ++i){
		
		eNum = rE[from][i];
//cout << "(" << from << "," << i << ")(" << eNum << ")" << endl;
		if( eNum >= 0 ){
			ansTemp = solve(i,c-y[eNum]);
			if(ansTemp != -1 ){//たどり着けた
				ansTemp += m[eNum];
				if( ans == -1 || ans > ansTemp){
					ans = ansTemp;
				}
			}
			//cout << i << " " << ansTemp << endl;
		}
	}
	if( ans != -1){
		dp[from][c] = 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];
	rep(i,E)cin>>t[i];
	rep(i,E)cin>>y[i];
	rep(i,E)cin>>m[i];

	//250
	rep(i,51)rep(j,51)rE[i][j] = -1;
	
	//1500
	rep(i,E){
		rE[s[i]][t[i]] = i;//道番号をいれておく
	}
	//
	rep(i,51)rep(j,301)dp[i][j] = dpINF;//
	
	//1からNへ行きたい決まっている
	//ペアソート?
	//特急と鈍行
	//最終的にコスト内であればよい
	/*cout << "----" << endl;
	rep(i,N+1){
		rep(j,N+1)cout << rE[i][j] << " ";
		cout << endl;
	}
	*/
	//cout << "----" << endl;
	
	P(solve(1,C));

	return 0;
}
0