結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 55;
const int MAX_C = 305;

struct edge
{
    int to,cost,tm;
};

int dp[MAX_N][MAX_C];
vector<edge> G[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c,v;
    cin >> n >> c >> v;
    vector<int> s(v),t(v),y(v),m(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){
        G[s[i]-1].pb((edge){t[i]-1,y[i],m[i]});
    }
    rep(i,n+1){
        rep(j,c+1){
            dp[i][j] = INF;
        }
    }
    dp[0][c] = 0;
    rep(i,n){
        rep(j,c+1){
            rep(k,G[i].size()){
                if(j >= G[i][k].cost){
                    dp[G[i][k].to][j-G[i][k].cost] = min(dp[G[i][k].to][j-G[i][k].cost],dp[i][j]+G[i][k].tm);
                }
            }
        }
    }
    int ans = INF;
    rep(i,c+1){
        ans = min(ans,dp[n-1][i]);
    }
    if(ans == INF){
        cout << "-1\n";
    }else{
        cout << ans << endl;
    }
    return 0;
}
0