結果

問題 No.1 道のショートカット
ユーザー d2verbd2verb
提出日時 2015-05-05 00:17:54
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,387 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 86,128 KB
実行使用メモリ 7,820 KB
最終ジャッジ日時 2023-09-22 12:09:39
合計ジャッジ時間 12,968 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
int ans = INF;

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];

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

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));
    }

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