結果

問題 No.1 道のショートカット
ユーザー PachicobuePachicobue
提出日時 2017-03-13 21:38:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,378 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 65,692 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-22 13:06:49
合計ジャッジ時間 2,574 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
typedef long long ll;

#define NMAX 51
#define MAX 101
#define CMAX 301

int N, C, V;
int S[MAX];
int T[MAX];
int Y[MAX];
int M[MAX];

int data[NMAX][CMAX];
struct edge {
    int to;
    int cost;
    int tim;
};
vector<edge> edges[NMAX];

void dfs(int start)
{
    for (const auto& i : edges[start]) {
        const int to = i.to;
        const int cost = i.cost;
        const int tim = i.tim;
        FOR(c, cost, C + 1)
        {
            if (data[to][c] == -1) {
                if (data[start][c - cost] != -1) {
                    data[to][c] = data[start][c - cost] + tim;
                }
            } else {
                if (data[start][c - cost] != -1) {
                    chmin(data[to][c], data[start][c - cost] + tim);
                }
            }
        }
        dfs(to);
    }
}

int main()
{
    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];
    }
    rep(i, V)
    {
        edges[T[i]].pb(edge{S[i], Y[i], M[i]});
    }
    rep(i, N)
    {
        rep(j, C + 1)
        {
            data[i][j] = -1;
        }
    }
    rep(j, C + 1)
    {
        data[N][j] = 0;
    }

    dfs(N);
    if (data[1][C] == -1) {
        cout << -1 << endl;
    } else {
        cout << data[1][C] << endl;
    }

    return 0;
}
0