結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
Ysmr_Ry
|
| 提出日時 | 2014-12-12 10:12:34 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,078 bytes |
| 記録 | |
| コンパイル時間 | 374 ms |
| コンパイル使用メモリ | 70,128 KB |
| 実行使用メモリ | 76,528 KB |
| 最終ジャッジ日時 | 2026-04-03 01:14:59 |
| 合計ジャッジ時間 | 1,369 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include<cstdio>
#include<algorithm>
#include<limits>
#include<utility>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)
const int INF = std::numeric_limits<int>::max();
template<class T>
void chmin( T &a, T b )
{ a = std::min( a, b ); return; }
struct edge
{
int to, cost, tim;
edge( int to, int cost, int tim )
: to(to), cost(cost), tim(tim)
{}
};
int N, C, V;
std::vector<edge> G[50];
int S[1500], T[1500], Y[1500], M[1500];
int main()
{
scanf( "%d%d%d", &N, &C, &V );
rep( i, V )
scanf( "%d", S+i );
rep( i, V )
scanf( "%d", T+i );
rep( i, V )
scanf( "%d", Y+i );
rep( i, V )
scanf( "%d", M+i );
rep( i, V )
G[S[i]-1].push_back( edge( T[i]-1, Y[i], M[i] ) );
std::vector<std::vector<int> > dp( N, std::vector<int>( C+1, INF ) );
rep( j, C+1 )
dp[0][j] = 0;
rep( i, N ) rep( k, C+1 ) if( dp[i][k] != INF ) rep( j, G[i].size() ) if( k+G[i][j].cost <= C )
chmin( dp[G[i][j].to][k+G[i][j].cost], dp[i][k]+G[i][j].tim );
printf( "%d\n", dp[N-1][C]==INF?-1:dp[N-1][C] );
return 0;
}
Ysmr_Ry