結果

問題 No.1 道のショートカット
ユーザー furonfuron
提出日時 2023-05-19 20:52:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,674 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 131,480 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-22 23:12:39
合計ジャッジ時間 3,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
//const int MOD = 998244353;

struct Edge {
	int to;
	int cost;
	int time;
};

using Graph = vector<vector<Edge>>;

int main() {
	int n, c, v;
	cin >> n >> c >> v;
	vi s(v), t(v), y(v), m(v);
	for (int i = 0; i < v; i++) cin >> s[i];
	for (int i = 0; i < v; i++) cin >> t[i];
	for (int i = 0; i < v; i++) cin >> y[i];
	for (int i = 0; i < v; i++) cin >> m[i];

	Graph g(n + 1);
	for (int i = 0; i < v; i++) {
		g[s[i]].push_back({ t[i],y[i],m[i] });
	}
	vvi dp(n + 1, vi(c + 1, inf));
	dp[1][0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= c; j++) {
			if (dp[i][j] == inf) continue;
			for (auto& u : g[i]) {
				if (j + u.cost > c) continue;
				dp[u.to][j + u.cost] = min(dp[u.to][j + u.cost], dp[i][j] + u.time);
			}
		}
	}
	int ans = inf;
	for (int i = 0; i <= c; i++) {
		ans = min(ans, dp[n][i]);
	}
	if (ans == inf) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}
0