結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2021-08-05 10:40:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 2,020 ms |
コンパイル使用メモリ | 200,620 KB |
最終ジャッジ日時 | 2025-01-23 14:12:45 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using i64 = std::int64_t; using vi64 = std::vector<i64>; using vvi64 = std::vector<vi64>; int main() { using namespace std; const i64 inf = 1e9; i64 n, c, v; cin >> n >> c >> v; vi64 s(v); for (i64 i = 0; i < v; i++) { cin >> s[i]; s[i]--; } vvi64 t(n), y(n), m(n); i64 x; for (i64 i = 0; i < v; i++) { cin >> x; x--; t[s[i]].push_back(x); } for (i64 i = 0; i < v; i++) { cin >> x; y[s[i]].push_back(x); } for (i64 i = 0; i < v; i++) { cin >> x; m[s[i]].push_back(x); } vvi64 dp(n, vi64(c + 1, inf)); dp[0][c] = 0; for (i64 i = 0; i < n; i++) { for (i64 j = 0; j < (c + 1); j++) { if (dp[i][j] == inf) continue; for (i64 k = 0; k < t[i].size(); k++) { i64 to = t[i][k], cost = j - y[i][k]; if (cost >= 0) { dp[to][cost] = min(dp[to][cost], dp[i][j] + m[i][k]); } } } } i64 ans = inf; for (i64 i = 0; i < (c + 1); i++) ans = min(ans, dp[n - 1][i]); if (ans == inf) cout << "-1\n"; else cout << ans << '\n'; }