結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2017-10-16 21:34:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,710 bytes |
コンパイル時間 | 1,811 ms |
コンパイル使用メモリ | 175,956 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:33:58 |
合計ジャッジ時間 | 2,494 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define times(n, i) uptil(0, n, i) #define rtimes(n, i) downto((n) - 1, 0, i) #define upto(f, t, i) for(int i##_to_ = (t), i = (f); i <= i##_to_; i++) #define uptil(f, t, i) for(int i##_to_ = (t), i = (f); i < i##_to_; i++) #define downto(f, t, i) for(int i##_to_ = (t), i = (f); i >= i##_to_; i--) #define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i > i##_to_; i--) typedef long double LD; #define long long long #if defined(EBUG) && !defined(ONLINE_JUDGE) #define debug true #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 2 #define _LIBCPP_DEBUG2 2 #define ln << endl #else #define debug false #define ln << '\n' #endif #define tb << '\t' #define sp << ' ' signed main() { // long: 64bit if(!debug) { cin.tie(0); ios::sync_with_stdio(0); } int N, C, V; scanf("%d%d%d", &N, &C, &V); vector<long> S(V); times(V, i) { scanf("%lld", &S[i]); --S[i]; } vector<long> T(V); times(V, i) { scanf("%lld", &T[i]); --T[i]; } vector<long> Y(V); times(V, i) scanf("%lld", &Y[i]); vector<long> M(V); times(V, i) scanf("%lld", &M[i]); vector<vector<int>> path(N); times(V, i) path[S[i]].push_back(i); vector<vector<long>> time(N, vector<long>(C+1, LLONG_MAX/2)); time[0][0] = 0; times(N, i) { for(int j : path[i]) { upto(0, C - Y[j], k) { time[T[j]][k + Y[j]] = min(time[T[j]][k + Y[j]], time[i][k] + M[j]); } } if(debug) { times(C+1, j) cout << (j?" ":"") << time[i][j]; cout ln; } } long ans = *min_element(time[N-1].begin(), time[N-1].end()); cout << (ans >= LLONG_MAX/2 ? -1 : ans) ln; return 0; }