結果

問題 No.1 道のショートカット
ユーザー Ai3Shota
提出日時 2018-05-18 00:17:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,290 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 162,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:36:03
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef struct{ int corrent, next, money, tim; }EDGE;
EDGE edge[1500];
vector<vector<EDGE>> root(51); 

int N, C, V;
int dp[51][301];

int main(void){
    
    cin >> N >> C >> V;
    for(int i = 0; i < V; ++i) cin >> edge[i].corrent;
    for(int i = 0; i < V; ++i) cin >> edge[i].next;
    for(int i = 0; i < V; ++i) cin >> edge[i].money;
    for(int i = 0; i < V; ++i) cin >> edge[i].tim;
    
    for(int i = 0; i < V; ++i) root[edge[i].corrent].push_back(edge[i]);
    
    for(int i = 0; i < 51; ++i) for(int j = 0; j < 301; ++j) dp[i][j] = INT_MAX;
    
    dp[1][0] = 0;
    for(int i = 1; i <= N; ++i){
        for(int j = 0; j <= C; ++j){
            if(dp[i][j] != INT_MAX){
                for(int k = 0; k < root[i].size(); ++k){
                    int next = root[i][k].next;
                    int money = root[i][k].money;
                    int tim = root[i][k].tim;
                    if(j + money <= C) dp[next][j + money] = min(dp[i][j] + tim, dp[next][j + money]);
                }
            }
        }
    }
    
    int result = INT_MAX;
    for(int i = 0; i <= C; ++i) result = min(result, dp[N][i]);
    if(result == INT_MAX) cout << -1 << endl;
    else cout << result << endl;
    
    
    return 0;
    
}
0