結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-01-14 08:55:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,628 bytes |
| コンパイル時間 | 488 ms |
| コンパイル使用メモリ | 61,732 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:19:21 |
| 合計ジャッジ時間 | 1,736 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <limits.h>
#include <cstdio>
#include <vector>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int test = 0;
typedef struct root {
int preCity;
int money;
int time;
}Root;
struct town {
vector<Root> root;
};
int N,C,V;
int S[1505];
int T[1505];
int Y[1505];
int M[1505];
struct town town[55];
int dp[55][305] = {0};
int main(void)
{
int i,j,k,l;
cin >> N >> C >> V;
/*
for(i=0;i<20;i++) {
printf("town[%d].root.size() = %d\n",i,town[i].root.size());
} */
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) {
Root tmp = {S[i],Y[i],M[i]};
town[T[i]].root.push_back(tmp);
}
rep(i,C+1) {
dp[1][i] = INT_MAX;
}
dp[1][C] = 0;
REP(i,2,N+1) {
rep(l,C+1) {
dp[i][l] = INT_MAX;
int n = town[i].root.size();
for(k=0;k<n;k++) {
if(dp[town[i].root[k].preCity][l]== INT_MAX) continue;
if(l+1 - town[i].root[k].money > 0) {
dp[i][ l - town[i].root[k].money ]
= min(dp[town[i].root[k].preCity][l] + town[i].root[k].time
,dp[i][ l - town[i].root[k].money ]);
}
}
}
}
int minMoney = INT_MAX;
rep(i,C+1) {
if(minMoney > dp[N][i]) minMoney = dp[N][i];
}
if(minMoney == INT_MAX) minMoney = -1;
printf("%d\n",minMoney);
/*
rep(i,N) {
rep(j,town[i].root.size()) {
printf("%d",i);
printf(" %d",town[i].root[j].nextCity);
printf(" %d",town[i].root[j].money);
printf(" %d\n",town[i].root[j].time);
}
}
*/
return 0;
}