結果

問題 No.1 道のショートカット
ユーザー kenken714kenken714
提出日時 2019-04-17 18:50:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,833 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 88,552 KB
実行使用メモリ 6,576 KB
最終ジャッジ日時 2023-09-27 22:18:37
合計ジャッジ時間 2,092 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,996 KB
testcase_01 AC 2 ms
6,016 KB
testcase_02 AC 3 ms
5,956 KB
testcase_03 AC 3 ms
6,272 KB
testcase_04 AC 3 ms
5,952 KB
testcase_05 AC 2 ms
6,076 KB
testcase_06 AC 2 ms
5,960 KB
testcase_07 AC 3 ms
6,096 KB
testcase_08 AC 4 ms
6,184 KB
testcase_09 AC 4 ms
6,156 KB
testcase_10 AC 7 ms
6,288 KB
testcase_11 AC 7 ms
6,576 KB
testcase_12 AC 6 ms
6,340 KB
testcase_13 AC 6 ms
6,348 KB
testcase_14 AC 2 ms
6,012 KB
testcase_15 AC 3 ms
6,224 KB
testcase_16 AC 3 ms
6,132 KB
testcase_17 AC 3 ms
6,000 KB
testcase_18 AC 3 ms
6,188 KB
testcase_19 AC 3 ms
6,228 KB
testcase_20 AC 3 ms
6,164 KB
testcase_21 AC 2 ms
6,060 KB
testcase_22 AC 3 ms
6,068 KB
testcase_23 AC 5 ms
6,544 KB
testcase_24 AC 5 ms
6,212 KB
testcase_25 AC 3 ms
6,140 KB
testcase_26 AC 3 ms
6,076 KB
testcase_27 AC 7 ms
6,260 KB
testcase_28 AC 3 ms
5,996 KB
testcase_29 AC 6 ms
6,240 KB
testcase_30 AC 3 ms
6,064 KB
testcase_31 AC 4 ms
6,116 KB
testcase_32 AC 4 ms
6,284 KB
testcase_33 AC 4 ms
6,176 KB
testcase_34 AC 6 ms
6,244 KB
testcase_35 AC 3 ms
6,072 KB
testcase_36 AC 6 ms
6,236 KB
testcase_37 AC 4 ms
6,092 KB
testcase_38 AC 3 ms
6,208 KB
testcase_39 AC 3 ms
6,140 KB
testcase_40 AC 4 ms
6,184 KB
testcase_41 AC 3 ms
6,052 KB
testcase_42 AC 3 ms
6,020 KB
testcase_43 AC 3 ms
6,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, c, m, ans = INF;
#define PP pair<ll, P>
ll d[60][310]; // 結果
struct edge { ll to, cost, coin; };
vector<edge> g[110000]; //隣接リスト to, cost

void dijkstra(ll a) { //実装汚いからそのうち直す
	priority_queue<PP, vector<PP>, greater<PP> > q; // to, cost, 条件
	REP(i, n)fill(d[i], d[i] + 310, INF);

	d[a][0] = 0;
	q.push(PP(0, P(a, 0)));
	while (!q.empty()) {
		PP p = q.top();
		q.pop();
		ll v = p.second.first;
		if (d[v][p.second.second] < p.first) continue;
		REP(i, g[v].size()) {
			edge e = g[v][i];
			if (p.second.second + e.coin > 300)continue;
			if (d[e.to][p.second.second + e.coin] > d[v][p.second.second] + e.cost) {
				d[e.to][p.second.second + e.coin] = d[v][p.second.second] + e.cost;
				q.push(PP(d[e.to][p.second.second + e.coin], P(e.to, p.second.second + e.coin)));
			}
		}
	}
}

int main() {
	cin >> n >> c >> m;
	vector<ll> i1(m), i2(m), i3(m), i4(m);
	REP(i, m) {
		cin >> i1[i];
		i1[i]--;
	}
	REP(i, m) {
		cin >> i2[i];
		i2[i]--;
	}
	REP(i, m) cin >> i3[i];
	REP(i, m) cin >> i4[i];
	REP(i, m) g[i1[i]].push_back({ i2[i],i4[i],i3[i] });
	dijkstra(0);
	REP(i, c + 1)ans = min(ans, d[n - 1][i]);
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
}


0