結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-04 23:00:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,199 bytes |
| コンパイル時間 | 1,422 ms |
| コンパイル使用メモリ | 164,956 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-08 05:02:59 |
| 合計ジャッジ時間 | 4,081 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 30 WA * 5 RE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(void) {
struct edge {
int from, cost, time;
};
int N,C,V;
cin >> N; cin >> C; cin >> V;
int 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++) S[i]--;
for(int i=0; i<V; i++) cin >> T[i];
for(int i=0; i<V; i++) T[i]--;
for(int i=0; i<V; i++) cin >> Y[i];
for(int i=0; i<V; i++) cin >> M[i];
vector< vector <edge> > e(V);
for(int i=0; i<V; i++) {
edge memo;
memo.from = S[i];
memo.cost = Y[i];
memo.time = M[i];
e[T[i]].push_back(memo);
}
int dp[N][C];
for(int i=0; i<N; i++) for(int j=0; j<C; j++) dp[i][j] = 1000000000;
for(int i=0; i<N; i++) {
if(i==0) {
dp[0][0] = 0;
continue;
}
for(int j=0; j<e[i].size(); j++) {
int f=e[i][j].from, c=e[i][j].cost, t=e[i][j].time;
for(int k=c; k<=C; k++) dp[i][k] = min(dp[i][k], dp[f][k-c] + t);
}
}
int ans=1000000000;
for(int i=0; i<C; i++) ans = min(ans, dp[N-1][i]);
if(ans == INT_MAX) cout << -1 << endl;
else cout << ans << endl;
return 0;
}