結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2017-05-19 13:06:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,600 bytes |
コンパイル時間 | 1,567 ms |
コンパイル使用メモリ | 167,160 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 16:29:54 |
合計ジャッジ時間 | 2,335 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int nextInt()’: main.cpp:9:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int nextInt() { int x; scanf("%d", &x); return x;} | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;} template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;} int nextInt() { int x; scanf("%d", &x); return x;} int memo[51][310]; struct State { int pos, dist, money; bool operator < (const State& o) const { return dist > o.dist; } int& ref() { return memo[pos][money]; } }; int S[1500], T[1500], Y[1500], M[1500]; struct E { int s, t, y, m; }; vector<E> es[51]; int main2() { REP(i, 51) es[i].clear(); int N = nextInt(); int C = nextInt(); int V = nextInt(); REP(i, V) S[i] = nextInt(); REP(i, V) T[i] = nextInt(); REP(i, V) Y[i] = nextInt(); REP(i, V) M[i] = nextInt(); REP(i, V) { es[S[i]].push_back( (E){S[i], T[i], Y[i], M[i]} ); } const int INF = 987654321; REP(i, 51) REP(j, 310) memo[i][j] = INF; int ans = INF; priority_queue<State> pq; pq.push( (State){1, 0, 0} ); memo[1][0] = 0; while (!pq.empty()) { State cur = pq.top(); pq.pop(); if (cur.dist != cur.ref()) continue; if (cur.pos == N) { ans = cur.dist; break; } for (E e : es[cur.pos]) { State next = (State) { e.t, cur.dist + e.m, cur.money + e.y }; if (next.money > C) continue; if (next.ref() <= next.dist) continue; next.ref() = next.dist; pq.push(next); } } if (ans >= INF / 2) ans = -1; cout << ans << endl; return 0; } int main() { for (;!cin.eof();cin>>ws) main2(); return 0; }