結果

問題 No.1 道のショートカット
ユーザー yukitfyukitf
提出日時 2020-07-22 15:57:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,993 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 185,980 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:31:21
合計ジャッジ時間 3,506 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 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,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,384 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 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 vl  = 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 N, C, V; 
vector<vector<tuple<int, int, int>>> G;
vector<bool> visited;
vector<int> sorted;
int sp = 0;

void dfs(int n)
{
    visited[n] = true;
    for(auto e : G[n])
    {
        int to, y, m;
        tie(to, y, m) = e;
        if(!visited[to]) dfs(to);
    }
    sorted[sp++] = n;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    
    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];
    G.resize(N);
    REP(i, V)
    {
        G[S[i]].pb(mt(T[i], Y[i], M[i]));
    }

    visited.resize(N, false);
    sorted.resize(N);
    dfs(0);
    reverse(ALL(sorted));

    vector<vi> dp(N, vi(C+1, INF));
    dp[0][C] = 0;

    REP(i, N)
    {
        int from = sorted[i]; 
        for(auto e : G[from])
        {
            int to, y, m;
            tie(to, y, m) = e;
            REP(c, C+1)
            {
                if (c >= y) chmin(dp[to][c-y], dp[from][c] + m);
            }
        }
    }

    int ans = INF;
    chmin(ans, *min_element(ALL(dp[N-1])));
    cout << ((ans != INF) ? ans : -1) << endl;
}
0