結果

問題 No.1 道のショートカット
ユーザー tarakojo1019tarakojo1019
提出日時 2021-01-18 16:17:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 2,132 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 125,080 KB
実行使用メモリ 9,884 KB
最終ジャッジ日時 2023-08-20 23:49:47
合計ジャッジ時間 3,375 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 14 ms
8,452 KB
testcase_09 AC 9 ms
5,896 KB
testcase_10 AC 6 ms
5,012 KB
testcase_11 AC 7 ms
5,580 KB
testcase_12 AC 19 ms
9,884 KB
testcase_13 AC 18 ms
9,384 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,716 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,708 KB
testcase_20 AC 4 ms
4,668 KB
testcase_21 AC 5 ms
4,580 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 11 ms
7,932 KB
testcase_24 AC 12 ms
8,524 KB
testcase_25 AC 8 ms
5,544 KB
testcase_26 AC 5 ms
4,680 KB
testcase_27 AC 13 ms
7,588 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 2 ms
4,504 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 11 ms
6,988 KB
testcase_33 AC 8 ms
5,688 KB
testcase_34 AC 10 ms
6,812 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 4 ms
4,876 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };



struct node {
	vector<ll> link;
	vector<ll> dist;
	ll d = 1e18;
	bool done = false;
};

struct edge {
	ll s;
	ll t;
	ll y;
	ll m;
};


int main() {
	ll N, C, V; cin >> N >> C >> V;
	auto ind = [&](ll n, ll c) {
		return n * (C+1) + c;
	};
	vector<node>nod(N * (C+1));
	vector<edge> ed(V);
	REP(i, 0, V) cin >> ed[i].s;
	REP(i, 0, V) cin >> ed[i].t;
	REP(i, 0, V) cin >> ed[i].y;
	REP(i, 0, V) cin >> ed[i].m;

	REP(i, 0, V) {
		REP(c, 0, C + 1) {
			if (c + ed[i].y > C) continue;
			nod[ind(ed[i].s - 1, c)].link.push_back(ind(ed[i].t - 1, c + ed[i].y));
			nod[ind(ed[i].s - 1, c)].dist.push_back(ed[i].m);
		}
	}

	auto cmp = [](auto a, auto b) {return a.first > b.first; };
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(cmp)> q{ cmp };

	nod[0].d = 0;
	q.push({ 0,0 });

	while (!q.empty()) {
		auto p = q.top();
		q.pop();

		if (nod[p.second].done) continue;
		ll i = p.second;
		nod[i].done = true;

		REP(j, 0, nod[i].link.size()) {
			ll c = nod[i].link[j];
			if (nod[c].done) continue;

			if (nod[c].d > nod[i].d + nod[i].dist[j]) {
				nod[c].d = nod[i].d + nod[i].dist[j];
				q.push({ nod[c].d, c });
			}
		}
	}

	ll ans = 1e18;
	REP(i, 0, C + 1) mins(ans, nod[ind(N - 1, i)].d);
	if (ans == (ll)1e18) PRI(-1);
	else PRI(ans);
	return 0;
}
0