結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2015-12-04 14:57:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,418 bytes |
コンパイル時間 | 1,655 ms |
コンパイル使用メモリ | 175,800 KB |
実行使用メモリ | 10,140 KB |
最終ジャッジ日時 | 2024-07-08 04:16:48 |
合計ジャッジ時間 | 12,658 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 RE * 1 TLE * 1 -- * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define loop for(;;) #define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl; #define all(v) begin(v),end(v) #define pb push_back #define inf (1e9) #define eps (1e-9) using Integer = long long; using Real = long double; const Real PI = acosl(-1); using P = pair<int, int>; template<class S, class T> inline ostream& operator<<(ostream&os, pair<S,T> p) { return os << '(' << p.first << ", " << p.second << ')'; } template<class S, class T> inline ostream& operator<<(ostream&os, tuple<S,T> t) { return os << '(' << get<0>(t) << ", " << get<1>(t) << ')'; } template<class S, class T, class U> inline ostream& operator<<(ostream&os, tuple<S,T,U> t) { return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')'; } template<class T> inline ostream& operator<<(ostream&os, set<T> v) { os << "(set"; for (T item: v) os << ' ' << item; os << ")"; return os; } template<class T> inline ostream& operator<<(ostream&os, vector<T> v) { if (v.size() == 0) { return os << "(empty)"; } os << v[0]; for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i]; return os; } template<class T> inline istream& operator>>(istream&is, vector<T>&v) { rep (i, v.size()) is >> v[i]; return is; } // ^ > v < int dx[] = { -1, 0, 1, 0 }; int dy[] = { 0, 1, 0, -1 }; using vi = vector<int>; using vvi = vector<vi>; using vd = vector<double>; using vvd = vector<vd>; using vb = vector<bool>; int main() { int n, c, v; cin >> n >> c >> v; vi ss(v), ts(v), ys(v), ms(v); cin >> ss >> ts >> ys >> ms; using Edge = tuple<int, int, int>; vector<vector<Edge>> neigh(v); rep (i, v) { neigh[ss[i]-1].push_back(make_tuple( ts[i]-1, ys[i], ms[i] )); } using Time = int; Time table[303][n]; rep (c, 303) rep (i, n) table[c][i] = inf; table[c][0] = 0; stack<tuple<int, int>> s; s.push(make_tuple(c, 0)); while (not s.empty()) { int c, u; tie(c, u) = s.top(); s.pop(); for (Edge&e: neigh[u]) { int v, y, m; tie(v,y,m) = e; if (c - y < 0) continue; table[c-y][v] = min(table[c-y][v], table[c][u] + m); s.push(make_tuple(c-y, v)); } } Time ans = inf; rep (k, c+1) { if (table[k][n-1] == inf) continue; ans = min(ans, table[k][n-1]); } cout<<(ans<inf?ans:-1)<< endl; return 0; }