結果

問題 No.1 道のショートカット
ユーザー kyave3kyave3
提出日時 2014-12-03 21:28:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,401 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 78,484 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:36:54
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define REPS(i,n) for (int i = 0; i <= (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define FORS(i,s,n) for (int i = (s); i <= (n); i++)

const int E = 1500;
int n, c, v, s[E], t[E], y[E], m[E];

struct edge {
    int to, cost, dist;
    edge(int to, int cost, int dist) : to(to), cost(cost), dist(dist) {}
};
typedef vector<vector<edge> > graph;
graph G;

const int N = 50;
const int C = 300;
const int inf = int(1e9);
int dp[N][C + 1];

int main() {
    int n,c,v;
    cin >> n >> c >> v;
    REP(i, v) cin >> s[i];
    REP(i, v) cin >> t[i];
    REP(i, v) cin >> y[i];
    REP(i, v) cin >> m[i];
    
    G.assign(n, vector<edge>());
    REP(i, v) G[s[i]-1].emplace_back(t[i]-1,y[i],m[i]);
    
    fill((int*)dp, (int*)dp+N*(C+1), inf);
    dp[0][0] = 0;
    
    REP(i, n) for(const auto &e : G[i]) REPS(k, c) {
        if(e.cost+k > c) continue;
        dp[e.to][e.cost+k] = min(dp[e.to][e.cost+k], dp[i][k]+e.dist);
    }
    
    int ans = *min_element(dp[n-1],dp[n-1]+c+1);
    cout << (ans == inf ? -1 : ans) << endl;
    
    return 0;
}
0