結果

問題 No.1 道のショートカット
ユーザー A8pfA8pf
提出日時 2018-10-02 10:10:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,422 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 83,224 KB
実行使用メモリ 107,008 KB
最終ジャッジ日時 2023-09-22 13:24:20
合計ジャッジ時間 7,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> T;//時間、所持金、座標

class Edge
{
	public:
	int cost;
	int time;
	int from;
	int to;

	Edge(int n,int t,int c)
	{
		to=n;
		time=t;
		cost=c;
	}

	Edge(int f,int t,int tt,int c)
	{
		from=f;
		to=t;
		time=tt;
		cost=c;
	}
};

vector<Edge> g[50];
int d[50];
int ss[1500];
int tt[1500];
int yy[1500];
int mm[1500];
int main()
{
	int n,c,m;
	cin>>n>>c>>m;
	for(int i=0;i<m;i++)
	{
		cin>>ss[i];
		ss[i]--;
	}
	for(int i=0;i<m;i++)
	{
		cin>>tt[i];
		tt[i]--;
	}
	for(int i=0;i<m;i++)
		cin>>yy[i];
	for(int i=0;i<m;i++)
		cin>>mm[i];
	for(int i=0;i<m;i++)
	{
		g[ss[i]].push_back(Edge(tt[i],mm[i],yy[i]));
	}

	//ここからダイクストラ
	fill(d,d+50,1e9-1);
	d[0]=0;
	priority_queue<T,vector<T>,greater<T>> que;
	que.push(make_tuple(0,c,0));
	while(!que.empty())
	{
		T cp=que.top();que.pop();
		int now=get<2>(cp);
		int zan=get<1>(cp);
		int lap=get<0>(cp);
		//cerr<<now<<endl;
		for(int i=0;i<g[now].size();i++)
		{
			Edge e=g[now][i];
			if(zan-e.cost>=0 && lap+e.time<=d[e.to]+150)
			{
				que.push(make_tuple(lap+e.time,zan-e.cost,e.to));
				d[e.to]=min(d[e.to],lap+e.time);
			}
		}
	}
	//ダイクストラ終了
	if(d[n-1]==1e9-1)
		cout<<-1<<endl;
	else
		cout<<d[n-1]<<endl;
	return 0;
}
0