結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2015-10-02 16:56:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,580 bytes |
コンパイル時間 | 932 ms |
コンパイル使用メモリ | 93,784 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-08 04:14:56 |
合計ジャッジ時間 | 8,875 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 40 |
ソースコード
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <numeric> #include <functional> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #define repd(i,a,b) for (int (i)=(a);(i)<(b);(i)++) #define rep(i,n) repd((i),0,(n)) #define inf 1000000000 typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; }; template <typename T> void output(T a, int precision) { if(precision > 0){ cout << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } int main() { // source code int N, C, V; cin >> N >> C >> V; vector<int> S, T, Y, M; rep(i, V) S[i] = inputValue(); rep(i, V) T[i] = inputValue(); rep(i, V) Y[i] = inputValue(); rep(i, V) M[i] = inputValue(); vector<vector<pair<int, pair<int, int>>>> edge(N); rep(i, V){ edge[S[i] - 1].push_back(make_pair(T[i] - 1, make_pair(Y[i], M[i]))); } vector<vector<int>> dp(N, vector<int>(C + 1, inf)); dp[0][C] = 0; rep(i, N){ rep(j, C + 1){ if (dp[i][j] == inf) continue; for (auto &k : edge[i]) { if (j - k.second.first >= 0) { dp[k.first][j - k.second.first] = min(dp[k.first][j - k.second.first], dp[i][j] + k.second.second); } } } } int ret = inf; rep(i, C + 1){ ret = min(ret, dp[N - 1][i]); } if(ret == inf) output(-1, 0); else output(ret, 0); return 0; }