結果

問題 No.1 道のショートカット
ユーザー IL_msta
提出日時 2015-05-30 12:09:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,808 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 64,628 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-08 04:02:18
合計ジャッジ時間 2,074 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

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 c){
	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 next = from + 1; next <= maxN; ++next){
		eNum = rE[from][next];//[0,E)
		if( eNum >= 0 ){
			ansTemp = solve( next, c-y[eNum]);//next->Nまでのコスト
			if(ansTemp != -1 ){//たどり着けた
				ansTemp += m[eNum];//from->nextのコストを足す
				if( ans == -1 || ans > ansTemp){
					ans = ansTemp;
				}
			}
		}
	}

	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 [0,50] [0,50] 初期化
	rep(i,maxN+1)rep(j,maxN+1)rE[i][j] = -1;
	
	//1500
	rep(i,E){
		rE[s[i]][t[i]] = i;//道番号をいれておく
	}
	//[0,50][0,300] 15k+300+50+1 初期化
	rep(i,maxN+1)rep(j,301)dp[i][j] = dpINF;//
	
	P(solve(1,C));

	return 0;
}
0