結果

問題 No.1 道のショートカット
ユーザー tubo28tubo28
提出日時 2014-12-06 14:39:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 2,160 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 81,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:36:57
合計ジャッジ時間 2,271 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <sstream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

// グラフ用ヘッダ

typedef int Time;
typedef int Cost;
struct Edge {
    int src, dst;
    Time time;
    Cost cost;
    Edge(int src = 0, int dst = 0, Time time = 0, Cost cost = 0) :
        src(src), dst(dst), time(time), cost(cost) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.time != f.time ? e.time > f.time : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int V,E;
int C;

Graph g;

int S[1500],T[1500],Y[1500],M[1500];

// 頂点,お金 -> 時間の最小値
int dp[60][400];

int main(){
    while(cin>>V>>C>>E){
        Edges es(E);
        for(auto arr : {S,T,Y,M}){
            rep(i,E) cin >> arr[i];
        }
        rep(i,E){
            es[i] = Edge(S[i],T[i],M[i],Y[i]);
        }
        sort(all(es), [](const Edge& a, const Edge& b){
                return a.src < b.src;
            });

        rep(i,60)rep(j,400)dp[i][j] = 1<<29;
        dp[1][0] = 0;
        for(auto& e:es){
            for(int i=0;i<=C-e.cost;i++){
                dp[e.dst][i+e.cost] = min(dp[e.dst][i+e.cost], dp[e.src][i]+e.time);
            }
        }
        int ans = 1<<29;
        for(int i=0;i<=C;i++){
            ans = min(ans, dp[V][i]);
        }
        if(ans==1<<29)ans=-1;
        cout << ans << endl;
    }
}
0