結果

問題 No.1 道のショートカット
ユーザー imulanimulan
提出日時 2016-03-07 02:17:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,347 bytes
コンパイル時間 2,731 ms
コンパイル使用メモリ 154,956 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 21:53:19
合計ジャッジ時間 3,100 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

const int INF=100000000;

struct edge{ int to,time,cost; };
typedef pair<int,int> pi; //(頂点番号,お金)
typedef pair<int,pi> ppi; //最短距離,(頂点番号,お金)
vector<edge> G[50];

int main()
{
	int i;

	int n,c,v;
	cin >>n >>c >>v;

	vector<int> s(v),t(v),y(v),m(v);
	rep(i,v) scanf(" %d",&s[i]);
	rep(i,v) scanf(" %d",&t[i]);
	rep(i,v) scanf(" %d",&y[i]);
	rep(i,v) scanf(" %d",&m[i]);
	rep(i,v)
	{
		--s[i];
		--t[i];
		G[s[i]].pb(edge{t[i],m[i],y[i]});
	}

	//dijkstra
	int d[50][301];
	fill(d[0],d[50],INF);
	d[0][c]=0;
	priority_queue<ppi,vector<ppi>,greater<ppi>> que;
	que.push(ppi(0,pi(0,c)));
	while(!que.empty()){
		ppi p=que.top();
		que.pop();
		pi val=p.sc;

		if(d[val.fi][val.sc]<p.fi) continue;
		rep(i,G[val.fi].size())
		{
			edge e=G[val.fi][i];
			if(val.sc-e.cost>=0 && d[e.to][val.sc-e.cost]>d[val.fi][val.sc]+e.time)
			{
				d[e.to][val.sc-e.cost]=d[val.fi][val.sc]+e.time;
				que.push(ppi(d[e.to][val.sc-e.cost],pi(e.to,val.sc-e.cost)));
			}
		}
	}

	int ans=INF;
	rep(i,c+1) ans=min(ans,d[n-1][i]);
	if(ans==INF) ans=-1;
	printf("%d\n",ans);
}
0