結果

問題 No.1 道のショートカット
ユーザー kohei0418kohei0418
提出日時 2015-06-19 16:01:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,991 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 91,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:22:06
合計ジャッジ時間 2,440 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 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 1 ms
4,380 KB
testcase_06 AC 1 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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 2 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,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,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,376 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(k,a,b) for(int k=(a); k < (b); k++)
#define FORE(k,a,b) for(int k=(a); k <= (b); k++)
#define REP(k,a) for(int k=0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-10;


int main()
{
    int N, C, V; cin >> N >> C >> V;
    VI ss(V), ts(V), ys(V), ms(V);
    REP(i, V) cin >> ss[i];
    REP(i, V) cin >> ts[i];
    REP(i, V) cin >> ys[i];
    REP(i, V) cin >> ms[i];

    VVI costs(N, VI(N, INF)), times(N, VI(N, INF));
    REP(i, V) {
        costs[ss[i]-1][ts[i]-1] = ys[i];
        times[ss[i]-1][ts[i]-1] = ms[i];
    }

    VVI dp(N, VI(C+1, INF));
    dp[0][0] = 0;

    FOR(i, 1, N) {
        FOR(j, 0, i) {
            if(costs[j][i] < INF) {
                int cost = costs[j][i];
                int t = times[j][i];
                FORE(c, 0, C) {
                    if(c + cost <= C) {
                        dp[i][c + cost] = min(dp[i][c + cost], dp[j][c] + t);
                    }
                    else {
                        break;
                    }
                }
            }
        }
    }

    int res = INF;
    FORE(c, 0, C) {
        res = min(res, dp[N-1][c]);
    }
    if(res == INF) res = -1;
    cout << res << endl;

    return 0;
}
0