結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
sigma425
|
| 提出日時 | 2015-04-25 08:29:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 873 bytes |
| コンパイル時間 | 1,335 ms |
| コンパイル使用メモリ | 162,280 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:12:59 |
| 合計ジャッジ時間 | 2,555 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
struct edge{int to,cost,dist;};
int s[1500],t[1500],c[1500],d[1500],inf=1e9;
vector<edge> G[50];
int main(){
int N,C,M;
cin>>N>>C>>M;
rep(i,M) cin>>s[i];
rep(i,M) cin>>t[i];
rep(i,M) cin>>c[i];
rep(i,M) cin>>d[i];
rep(i,M){
G[s[i]-1].pb({t[i]-1,c[i],d[i]});
}
int D[50][301]={};
rep(i,N) rep(j,C+1) D[i][j]=inf;
D[0][0]=0;
rep(i,N-1) rep(j,C+1){
for(auto e:G[i]){
if(j+e.cost<=C) chmin(D[e.to][j+e.cost],D[i][j]+e.dist);
}
}
int ans=inf;
rep(j,C+1) chmin(ans,D[N-1][j]);
if(ans==inf) ans=-1;
cout<<ans<<endl;
}
sigma425