結果

問題 No.1 道のショートカット
ユーザー d2verbd2verb
提出日時 2015-05-05 00:54:11
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,630 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 84,964 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:09:15
合計ジャッジ時間 2,256 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int N, C, V, data[4][1500], memo[51][301];

struct edge{
    int to, cost, time;
    edge(int to, int cost, int time){
        this->to = to;
        this->cost = cost;
        this->time = time;
    }
};

vector<edge> G[51];

int solve(int n, int c){
    if(memo[n][c] != INF) return memo[n][c];

    if(n == N){
        if(c <= C) return 0;
        return INF;
    }
    
    if(c > C) return INF;
    
    int _min = INF;
    for(int i = 0; i < G[n].size(); i++){
        _min = min(solve(G[n][i].to, c + G[n][i].cost) + G[n][i].time, _min);
    }
    
    return memo[n][c] = _min;
}

void init(){
    for(int i = 0; i <= 50; i++){
        for(int j = 0; j <= 300; j++) memo[i][j] = INF;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin >> N >> C >> V;
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < V; j++) cin >> data[i][j];
    }

    for(int i = 0; i < V; i++){
        int s = data[0][i], t = data[1][i];
        int y = data[2][i], m = data[3][i];
        G[s].push_back(edge(t, y, m));
    }

    init();
    int ans = solve(1, 0);
    
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0