結果

問題 No.1 道のショートカット
ユーザー daleksprinterdaleksprinter
提出日時 2018-09-20 13:36:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,176 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 172,836 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 13:22:18
合計ジャッジ時間 3,054 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100009;
const int mod = 1000000007;

signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n; cin >> n;
    int c; cin >> c;
    int v; cin >> v;

    vector< vector<vector<int>> > edges(n);

    int data[4][v];
    rep(i,0,4){
        rep(j,0,v){
            cin >> data[i][j];
        }
    }
    

    rep(i,0,v){
        vector<int> tmp = {data[1][i]-1, data[2][i], data[3][i]};
        edges[data[0][i]-1].push_back(tmp);
    }

    int dp[c+1][n]; memset(dp,-1,sizeof(dp)); dp[0][0] = 0;
    
    rep(i,0,n){
        rep(j,0,c+1){
            if(dp[j][i] > -1){
                rep(k,0,edges[i].size()){
                    if(j + edges[i][k][1] < c+1){
                        dp[j + edges[i][k][1]][edges[i][k][0]] = dp[j][i] + edges[i][k][2];
                    }
                }
            }
        }
    }

    

    int ans = inf;
    rep(i,0,c+1){
        if(dp[i][n-1] > -1){
            ans = min(ans, dp[i][n-1]);
        }
    }

    cout << ((ans == inf) ? -1 : ans) << endl;


    
}   
0