結果

問題 No.1 道のショートカット
ユーザー tkzw_21
提出日時 2015-03-11 09:49:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,183 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 167,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 03:49:46
合計ジャッジ時間 7,555 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 7 RE * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
typedef long long ll;

const double EPS = 1e-8;
const int INF = 1e9;
const int MOD = 1e9+7;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};

struct edge{int to,cost,tm;};


int main(void) {
	int n,c,v;
	cin >> n >> c >> v;
	vector<int> s(n),t(n),y(n),m(n);
	for(int i=0;i<v;i++)cin >> s[i];
	for(int i=0;i<v;i++)cin >> t[i];
	for(int i=0;i<v;i++)cin >> y[i];
	for(int i=0;i<v;i++)cin >> m[i];

	for(int i=0;i<v;i++){
		s[i]--;t[i]--;
	}

	vector<vector<edge>> es(n);
	for(int i=0;i<v;i++){
		es[s[i]].push_back(edge{t[i],y[i],m[i]});
	}

	//dp[今いる場所][残りコスト] := 移動時間
	vector<vector<int>> dp(n,vector<int>(c+1,INF));
	dp[0][c] = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=c;j++){
			if(dp[i][j] == INF)continue;
			for(int k=0;k<es[i].size();k++){
				int to = es[i][k].to;
				int cost = es[i][k].cost;
				int tm = es[i][k].tm;
				if(j - cost < 0)continue;
				dp[to][j-cost] = min(dp[i][j]+tm,dp[to][j-cost]);
			}
		}
	}

	int ret = INF;
	for(int i=0;i<=c;i++){
		ret = min(ret,dp[n-1][i]);
	}

	cout << (ret==INF?-1:ret) << endl;
	return 0;
}
0