結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-06 18:21:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,980 bytes |
| コンパイル時間 | 746 ms |
| コンパイル使用メモリ | 70,760 KB |
| 実行使用メモリ | 474,156 KB |
| 最終ジャッジ日時 | 2024-07-08 05:03:43 |
| 合計ジャッジ時間 | 7,317 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 1 -- * 32 |
ソースコード
#include <iostream>
#include <climits>
#include <queue>
#include <vector>
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define p_int pair<int, int>
using namespace std;
int main(){
// 街の数、コスト上限、道の数
int city_n, c_max, load_n;
cin >> city_n >> c_max >> load_n;
// 始点、終点、コスト、時間
int s[load_n], t[load_n], c[load_n], time[load_n];
REP(i, 0, load_n) cin >> s[i];
REP(i, 0, load_n) cin >> t[i];
// sから行ける場所のvectorの配列
vector<p_int> st[city_n + 1];
REP(i, 0, load_n) st[s[i]].push_back(make_pair(t[i], i));
REP(i, 0, load_n) cin >> c[i];
REP(i, 0, load_n) cin >> time[i];
// 使った費用を縦軸、現在地を横軸に取ってDP
int dp[c_max + 1][city_n + 1];
REP(i, 0, c_max + 1){
REP(j, 0, city_n + 1){
dp[i][j] = INT_MAX;
}
}
dp[0][1] = 0;
queue<p_int> q;
q.push(make_pair(0, 1));
while (!(q.empty())){
// queueの先頭の要素を取り出し、そこから行ける都市を調べる
p_int front = q.front();
q.pop();
// 場所とそこまでのコスト
int c_front = front.first;
int s_front = front.second;
vector<p_int> t_goto = st[s_front];
REP(i, 0, t_goto.size()){
p_int t_goto_i = t_goto[i];
int t_next = t_goto_i.first;
int iter = t_goto_i.second;
int c_next = c_front + c[iter];
if (c_next <= c_max) {
int time_next = dp[c_front][s_front] + time[iter];
dp[c_next][t_next] = min(dp[c_next][t_next], time_next);
q.push(make_pair(c_next, t_next));
}
}
}
// dp[i][city_n]における最小値を返す
int ans = INT_MAX;
REP(i, 0, c_max + 1){
ans = min(ans, dp[i][city_n]);
}
if (ans == INT_MAX) cout << -1 << endl;
else cout << ans << endl;
return 0;
}