結果

問題 No.1 道のショートカット
ユーザー Yang33Yang33
提出日時 2017-05-25 20:12:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,837 bytes
コンパイル時間 1,184 ms
コンパイル使用メモリ 154,148 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 22:07:01
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  xtimex  Problem: yukicoder 001 / Link: http://yukicoder.me/problems/no/1  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N, C, V;
ll s[1500];
ll t[1500];
ll y[1500];
ll m[1500];
ll dist[310][50];
vector<pair<ll, pll>>G[50];
ll ans = LINF;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N >> C >> V;
	FOR(i, 0, V)cin >> s[i];
	FOR(i, 0, V)cin >> t[i];
	FOR(i, 0, V)cin >> y[i];
	FOR(i, 0, V)cin >> m[i];

	FOR(i, 0, V) {
		s[i]--; t[i]--;
		G[s[i]].push_back(mp(t[i], mp(y[i], m[i])));
	}

	FOR(i, 0, 310) {
		FOR(j, 0, 50)dist[i][j] = LINF;
	}

	priority_queue<pair<ll, pll>>q;//dist,v,c
	dist[0][0] = 0;
	q.push(mp(0, mp(0, 0)));
	while (!q.empty()) {
		pair<ll, pll>a = q.top(); q.pop();
		ll d = a.first;
		ll v = a.second.first;
		ll c = a.second.second;
		if (dist[c][v] < d)continue;
		FOR(i, 0, G[v].size()) {
			ll nv = G[v][i].first;
			ll pc = G[v][i].second.first;
			ll pd = G[v][i].second.second;
			if (c + pc > C)continue;
			if (dist[c + pc][nv] > dist[c][v] + pd) {
				dist[c + pc][nv] = dist[c][v] + pd;
				q.push(mp(dist[c + pc][nv], mp(nv, c + pc)));
			}
		}
	}

	FOR(i, 0, C + 1) {
		ans = min(ans, dist[i][N - 1]);
	}

	if (ans == LINF)ans = -1;
	cout << ans << endl;

	return 0;
}
0