結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
tokkaka
|
| 提出日時 | 2016-07-16 19:20:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,539 bytes |
| コンパイル時間 | 810 ms |
| コンパイル使用メモリ | 92,056 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-07-08 04:28:52 |
| 合計ジャッジ時間 | 2,019 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 WA * 17 RE * 1 |
ソースコード
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
using namespace std;
struct Road
{
int destination;
int cost;
int time;
Road() : destination(0), cost(0), time(0) {}
Road(int d, int c, int t) : destination(d), cost(c), time(t) {}
};
std::vector<std::vector<Road>> road;
std::vector<std::vector<tuple<int,int>>> dp;
enum {
arrival_time = 0,
min = 1
};
int solve(int start, int goal, int money, int time)
{
if(money < 0) return -1;
if(start == goal) return time;
if(road[start].empty()) return -1;
if(get<arrival_time>(dp[start][money]) != -2 && get<arrival_time>(dp[start][money]) < time)
return get<arrival_time>(dp[start][money]);
int min=INT_MAX;
for(const auto &r : road[start]) {
int t = solve(r.destination, goal, money-r.cost, time+r.time);
if(t < min && t != -1) min = t;
}
if(min == INT_MAX) min = -1;
dp[start][money] = make_tuple(time, min);
return min;
}
int main()
{
int N, C, V;
cin >> N >> C >> V;
std::vector<int> S(V), T(V), Y(V), M(V);
for(auto & s : S) cin >> s;
for(auto & t : T) cin >> t;
for(auto & y : Y) cin >> y;
for(auto & m : M) cin >> m;
road.resize(N+1);
for(int i=0; i<V; i++)
road[S[i]].push_back(Road(T[i], Y[i], M[i]));
dp.resize(V+1);
for(auto &a : dp) {
a.resize(C+1, make_tuple(-2, -2));
}
cout << solve(1, N, C, 0) << std::endl;
}
tokkaka