結果

問題 No.1 道のショートカット
ユーザー a_s_ka_s_k
提出日時 2023-11-07 04:29:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,239 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 211,428 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-07 04:29:58
合計ジャッジ時間 4,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,m,n) for(ll i=(ll)m;i<(ll)n;i++)
#define Endl endl
#define pr(i,j) make_pair(i,j) 
const ll mod = 998244353;
const ll inf = 5e18;
const ld pi = 3.14159265358979;
struct T {
	ll to;
	ll time;
	ll cost;
};
int main() {
	ll n, c, v;
	cin >> n >> c >> v;
	vector<vector<ll>>dp(c + 1, vector<ll>(n,inf));
	vector<vector<T>> g(n);
	vector<ll>s(v), t(v), y(v), m(v);
	rep(i, 0, v) {
		cin >> s[i];
		s[i]--;
	}
	rep(i, 0, v) {
		cin >> t[i];
		t[i]--;
	}
	rep(i, 0, v) {
		cin >> y[i];
	}
	rep(i, 0, v) {
		cin >> m[i];
	}
	rep(i, 0, v) {
		T in = {};
		in.cost = y[i];
		in.time = m[i];
		in.to = t[i];
		g[s[i]].push_back(in);
	}
	dp[0][0] = 0;
	rep(i, 0, c + 1) {
		rep(j, 0, n) {
			rep(k, 0, g[j].size()) {
				if (i + g[j][k].cost <= c) {
					dp[i + g[j][k].cost][g[j][k].to] = min(dp[i + g[j][k].cost][g[j][k].to], dp[i][j]+g[j][k].time);
				}
			}
		}
	}
	/*rep(i, 0, n) {
		rep(j, 0, c + 1) {
			if (dp[j][i] == inf)cout << "inf" << " ";
			else cout << dp[j][i] << " ";
		}
		cout << endl;
	}*/
	ll ans = inf;
	rep(i, 0, c + 1) {
		ans = min(ans, dp[i][n - 1]);
	}
	if (ans == inf)cout << -1 << endl;
	else cout << ans << endl;
}
0