結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
Yang33
|
| 提出日時 | 2017-05-25 20:12:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 5,000 ms |
| コード長 | 1,837 bytes |
| コンパイル時間 | 1,512 ms |
| コンパイル使用メモリ | 167,820 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:30:41 |
| 合計ジャッジ時間 | 2,333 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- xtimex Problem: yukicoder 001 / Link: http://yukicoder.me/problems/no/1 ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
ll N, C, V;
ll s[1500];
ll t[1500];
ll y[1500];
ll m[1500];
ll dist[310][50];
vector<pair<ll, pll>>G[50];
ll ans = LINF;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> N >> C >> V;
FOR(i, 0, V)cin >> s[i];
FOR(i, 0, V)cin >> t[i];
FOR(i, 0, V)cin >> y[i];
FOR(i, 0, V)cin >> m[i];
FOR(i, 0, V) {
s[i]--; t[i]--;
G[s[i]].push_back(mp(t[i], mp(y[i], m[i])));
}
FOR(i, 0, 310) {
FOR(j, 0, 50)dist[i][j] = LINF;
}
priority_queue<pair<ll, pll>>q;//dist,v,c
dist[0][0] = 0;
q.push(mp(0, mp(0, 0)));
while (!q.empty()) {
pair<ll, pll>a = q.top(); q.pop();
ll d = a.first;
ll v = a.second.first;
ll c = a.second.second;
if (dist[c][v] < d)continue;
FOR(i, 0, G[v].size()) {
ll nv = G[v][i].first;
ll pc = G[v][i].second.first;
ll pd = G[v][i].second.second;
if (c + pc > C)continue;
if (dist[c + pc][nv] > dist[c][v] + pd) {
dist[c + pc][nv] = dist[c][v] + pd;
q.push(mp(dist[c + pc][nv], mp(nv, c + pc)));
}
}
}
FOR(i, 0, C + 1) {
ans = min(ans, dist[i][N - 1]);
}
if (ans == LINF)ans = -1;
cout << ans << endl;
return 0;
}
Yang33