結果

問題 No.1 道のショートカット
ユーザー yogi_cgyogi_cg
提出日時 2020-03-28 00:46:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 659 ms / 5,000 ms
コード長 1,506 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 174,492 KB
実行使用メモリ 202,456 KB
最終ジャッジ日時 2023-09-27 22:27:30
合計ジャッジ時間 13,077 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
18,580 KB
testcase_01 AC 9 ms
18,796 KB
testcase_02 AC 8 ms
18,536 KB
testcase_03 AC 30 ms
45,840 KB
testcase_04 AC 8 ms
14,880 KB
testcase_05 AC 9 ms
18,672 KB
testcase_06 AC 30 ms
46,088 KB
testcase_07 AC 35 ms
45,984 KB
testcase_08 AC 543 ms
202,456 KB
testcase_09 AC 388 ms
202,328 KB
testcase_10 AC 463 ms
202,364 KB
testcase_11 AC 525 ms
190,628 KB
testcase_12 AC 659 ms
202,252 KB
testcase_13 AC 630 ms
202,356 KB
testcase_14 AC 79 ms
81,348 KB
testcase_15 AC 83 ms
167,320 KB
testcase_16 AC 206 ms
190,804 KB
testcase_17 AC 40 ms
77,408 KB
testcase_18 AC 147 ms
194,608 KB
testcase_19 AC 119 ms
155,436 KB
testcase_20 AC 198 ms
182,840 KB
testcase_21 AC 133 ms
139,916 KB
testcase_22 AC 96 ms
120,120 KB
testcase_23 AC 522 ms
93,080 KB
testcase_24 AC 421 ms
93,020 KB
testcase_25 AC 165 ms
112,564 KB
testcase_26 AC 112 ms
85,236 KB
testcase_27 AC 490 ms
190,620 KB
testcase_28 AC 45 ms
77,400 KB
testcase_29 AC 557 ms
120,468 KB
testcase_30 AC 153 ms
57,928 KB
testcase_31 AC 272 ms
30,436 KB
testcase_32 AC 373 ms
171,168 KB
testcase_33 AC 301 ms
151,740 KB
testcase_34 AC 481 ms
85,240 KB
testcase_35 AC 338 ms
14,756 KB
testcase_36 AC 406 ms
163,376 KB
testcase_37 AC 343 ms
96,912 KB
testcase_38 AC 95 ms
116,452 KB
testcase_39 AC 148 ms
159,536 KB
testcase_40 AC 243 ms
186,728 KB
testcase_41 AC 126 ms
135,916 KB
testcase_42 AC 21 ms
41,992 KB
testcase_43 AC 84 ms
167,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e10;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    typedef struct
    {
        int to, cost, time;
    } Edge;

    int N, C, V; cin >> N >> C >> V;
    vi S(V), T(V), Y(V), M(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];

    vector<vector<Edge>> E(N);
    REP(i, V)
    {
        E[S[i]-1].push_back(Edge{T[i]-1, Y[i], M[i]});
    }

    vvi dp(N, vi(500000, INF)); dp[0][0] = 0;
    REP(i, N-1)
    {
        REP(j, E[i].size())
        {
            REP(k, 500000)
            {
                if(dp[i][k] != INF) chmin(dp[E[i][j].to][k+E[i][j].cost], dp[i][k]+E[i][j].time);
            }
        }
    }
    int ans = INF;
    REP(i, C+1) chmin(ans, dp[N-1][i]);
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}
0