結果

問題 No.1 道のショートカット
ユーザー myantamyanta
提出日時 2017-04-30 07:41:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,597 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 50,476 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 13:07:23
合計ジャッジ時間 1,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,504 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
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 1 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,376 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,376 KB
testcase_36 WA -
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<vector>


using namespace std;


struct state_t
{
	int c, t;
};


struct road_t
{
	state_t s;
	int to;
};


struct city_t
{
	vector<road_t> road;
	vector<state_t> state;
};


vector<city_t> city;


int state_add(vector<state_t>& s, int c, int t)
{
	vector<int> remove;
	int is_add=0;

	for(int i=s.size()-1;i>=0;i--)
	{
		if(c>s[i].c && t<=s[i].t)
		{
			remove.push_back(i);
			is_add=1;
		}
		else if(c>=s[i].c && t<s[i].t)
		{
			remove.push_back(i);
			is_add=1;
		}
	}
	if(s.size()==0) is_add=1;

	for(unsigned i=0;i<remove.size();i++)
	{
		s.erase(s.begin()+remove[i]);
	}

	if(is_add) s.push_back((state_t){c, t});
	return is_add;
}


void solve(int x, int c, int t)
{
	if(state_add(city[x].state, c, t)==0) return;

	vector<road_t>& road=city[x].road;
	for(unsigned i=0;i<road.size();i++)
	{
		if(c-road[i].s.c<0) continue;
		solve(road[i].to, c-road[i].s.c, t+road[i].s.t);
	}
}


int main(void)
{
	int n, c, v;

	while(scanf("%d%d%d", &n, &c, &v)==3)
	{
		city.clear();
		city.resize(n+1);
		{
			vector<int> vs, vt, vy, vm;
			vs.resize(v);
			vt.resize(v);
			vy.resize(v);
			vm.resize(v);
			for(int i=0;i<v;i++) scanf("%d", &vs[i]);
			for(int i=0;i<v;i++) scanf("%d", &vt[i]);
			for(int i=0;i<v;i++) scanf("%d", &vy[i]);
			for(int i=0;i<v;i++) scanf("%d", &vm[i]);

			for(int i=0;i<v;i++)
			{
				city[vs[i]].road.push_back((road_t){{vy[i], vm[i]}, vt[i]});
			}
		}
		solve(1, c, 0);

		int t=-1;
		for(unsigned i=0;i<city[n].state.size();i++)
		{
			state_t& s=city[n].state[i];
			if(i==0 || t>s.t) t=s.t;
		}
		printf("%d\n", t);
	}

	return 0;
}
0