結果

問題 No.1 道のショートカット
コンテスト
ユーザー arudo
提出日時 2026-05-17 18:00:17
言語 C++23(gnu拡張)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,266 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,428 ms
コンパイル使用メモリ 344,244 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-17 18:00:25
合計ジャッジ時間 4,737 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h> 

using i64 = long long; 
using u64 = unsigned long long; 
using u32 = unsigned; 

using u128 = unsigned __int128; 
using i128 = __int128; 

constexpr int inf = 1e9 + 7;

struct Camino {
	int destino;
	int costo;
	int tiempo;
};

void solve() {
	int N, C, V;
	std::cin >> N >> C >> V;

	std::vector<int> S(V), T(V), Y(V), M(V);
	std::vector<std::vector<Camino>> adj(N + 1);

	for(int& x : S) std::cin >> x;
	for(int& x : T) std::cin >> x;
	for(int& x : Y) std::cin >> x;
	for(int& x : M) std::cin >> x;

	for(int i = 0; i < V; i ++) {
		adj[S[i]].push_back({T[i], Y[i], M[i]});
	}

	std::vector dp(N + 1, std::vector<int> (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 x : adj[i]) {
				if(j + x.costo <= C) {
					dp[x.destino][j + x.costo] = std::min(dp[x.destino][j + x.costo], dp[i][j] + x.tiempo);
				}
			}
		}
	}	

	int ans = inf;

	for(int i = 0; i <= C; i ++) {
		ans = std::min(ans, dp[N][i]);
	}

	if(ans == inf) {
		std::cout << -1 << "\n";
	}else std::cout << ans << "\n";
} 

int main() { 
	std::ios::sync_with_stdio(false); 
	std::cin.tie(nullptr); 

	int T = 1; 
	//std::cin >> T; 

	while (T--) { 
		solve(); 
	} 
	return 0; 
}
0