結果

問題 No.1 道のショートカット
ユーザー ichyo
提出日時 2015-04-08 00:19:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,915 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 161,268 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:11:56
合計ジャッジ時間 2,548 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N, C, V;
    while(cin >> N >> C >> V) {
        vector<int> S(V);
        REP(i, V) cin >> S[i];
        vector<int> T(V);
        REP(i, V) cin >> T[i];
        vector<int> Y(V);
        REP(i, V) cin >> Y[i];
        vector<int> M(V);
        REP(i, V) cin >> M[i];
        int dp[55][333] = {};
        C++;
        const int INF = 1000000000;
        REP(i, N) REP(j, C) dp[i][j] = INF;
        dp[0][0] = 0;

        REP(i, N) {
            REP(k, V) if(S[k]-1 == i) {
                REP(j, C) if(dp[i][j] < INF) {
                    int ni = T[k] - 1;
                    int nj = Y[k] + j;
                    if(nj < C) {
                        dp[ni][nj] = min(dp[ni][nj], dp[i][j] + M[k]);
                    }
                }
            }
        }
        int ans = INF;
        REP(j, C) ans = min(ans, dp[N-1][j]);
        if(ans == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

/* vim:set foldmethod=marker: */
0