結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-19 12:42:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,590 bytes |
| コンパイル時間 | 1,522 ms |
| コンパイル使用メモリ | 167,156 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-07-08 04:51:59 |
| 合計ジャッジ時間 | 2,258 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 WA * 2 |
コンパイルメッセージ
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, money;
bool operator < (const State& o) const {
return memo[pos][money] > memo[o.pos][o.money];
}
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} );
memo[1][0] = 0;
while (!pq.empty()) {
State cur = pq.top(); pq.pop();
if (cur.pos == N) {
ans = memo[cur.pos][cur.money];
break;
}
for (E e : es[cur.pos]) {
State next = (State) { e.t, cur.money + e.y };
if (next.money > C) continue;
if (next.ref() <= cur.ref() + e.m) continue;
next.ref() = cur.ref() + e.m;
pq.push(next);
}
}
if (ans >= INF / 2) ans = -1;
cout << ans << endl;
return 0;
}
int main() {
for (;!cin.eof();cin>>ws) main2();
return 0;
}