結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
maine_honzuki
|
| 提出日時 | 2020-05-03 01:14:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 5,000 ms |
| コード長 | 1,413 bytes |
| コンパイル時間 | 1,460 ms |
| コンパイル使用メモリ | 176,276 KB |
| 実行使用メモリ | 8,956 KB |
| 最終ジャッジ日時 | 2024-07-20 16:47:32 |
| 合計ジャッジ時間 | 2,762 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, C, V, S[1510], T[1510], Y[1510], M[1510];
cin >> N >> C >> V;
for (int i = 0; i < V; ++i)
cin >> S[i];
for (int i = 0; i < V; ++i)
cin >> T[i];
for (int i = 0; i < V; ++i)
cin >> Y[i];
for (int i = 0; i < V; ++i)
cin >> M[i];
struct road {
int nxt_town, nxt_money, time;
};
vector<road> G[52][302];
for (int i = 0; i < V; ++i) {
for (int j = 0; j <= C; ++j) {
if (j + Y[i] <= C) {
G[S[i]][j + Y[i]].push_back({T[i], j, M[i]});
}
}
}
int dp[52][302];
memset(dp, 1000000, sizeof(dp));
priority_queue<pair<int, pair<int, int>>,
vector<pair<int, pair<int, int>>>,
greater<pair<int, pair<int, int>>>>
que;
que.push({0, {1, C}});
while (!que.empty()) {
auto q = que.top();
que.pop();
int time = q.first;
auto now = q.second;
if (dp[now.first][now.second] < time) continue;
dp[now.first][now.second] = time;
for (auto& nxt : G[now.first][now.second]) {
que.push({time + nxt.time, {nxt.nxt_town, nxt.nxt_money}});
}
}
int ans = 1000000;
for (int i = 0; i <= C; i++) {
ans = min(ans, dp[N][i]);
}
if (ans == 1000000)
ans = -1;
cout << ans << endl;
}
maine_honzuki