結果

問題 No.1 道のショートカット
ユーザー yukitfyukitf
提出日時 2020-07-22 11:38:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,204 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 185,036 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 13:51:47
合計ジャッジ時間 3,794 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 N, C, V;
vector<vector<pi>> G;

int idx = 0;
vi sorted;
vector<bool> visited;

void dfs(int n)
{
    visited[n] = true;
    REP(i, N)
    {
        pi p = G[n][i];
        if(p.first != INF && p.second != INF)
        {
            if(!visited[i])dfs(i);
        }
    }
    sorted[idx++] = 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, vector<pi>(N, mp(INF, INF)));
    REP(i, V)
    {
        G[S[i]][T[i]] = mp(Y[i], M[i]);
    }

    // トポロジカルソート
    sorted.resize(N);
    visited.resize(N, false);
    dfs(0);
    reverse(ALL(sorted));
    //REP(i, N) cout << sorted[i] << " ";
    //cout << endl;

    vector<vi> time(N, vi(C+1, INF));
    time[sorted[0]][C] = 0;
    REP(i, N)
    {
        int n = sorted[i]; 
        REP(j, N)
        {
            pi p = G[n][j];
            REP(c, C+1)
            {
                if(c >= p.first) chmin(time[j][c-p.first], time[n][c] + p.second);
            }
        }
    }

    int m = 0;
    REP(i, N) if(sorted[i] == N-1) m = i;
    int ans = INF;
    REP(c, C+1)
    {
        chmin(ans, time[m][c]);
    }
    if(ans >= INF) cout << -1 << endl;
    else cout << ans << endl;
}
0