結果

問題 No.1 道のショートカット
ユーザー yukitfyukitf
提出日時 2020-07-22 15:26:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,691 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 180,736 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-22 13:51:25
合計ジャッジ時間 3,296 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

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

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    
    int N, C, V; cin >> N >> C >> V;
    vi S(V), T(V), Y(V), M(V);
    REP(i, V) cin >> S[i], S[i]--;
    REP(i, V) cin >> T[i], T[i]--;
    REP(i, V) cin >> Y[i];
    REP(i, V) cin >> M[i];
    vector<vector<pi>> G(N, vector<pi>(N, mp(INF, INF)));
    REP(i, V) G[S[i]][T[i]] = mp(Y[i], M[i]);

    vector<vi> dp(N, vi(C+1, INF));
    dp[0][C] = 0;
    queue<pi> q;
    q.push(mp(0, C));
    while(!q.empty())
    {
        pi p = q.front(); q.pop();
        int n, c;
        tie(n, c) = p;
        REP(i, N)
        {
            pi e = G[n][i];
            if(e != mp(INF, INF) && c >= e.first && chmin(dp[i][c-e.first], dp[n][c]+e.second)) q.push(mp(i, c-e.first));
        }
    }

    int ans = INF;
    REP(c, C+1) chmin(ans, dp[N-1][c]);
    cout << ((ans != INF) ? ans : -1) << endl;
}
0