結果
| 問題 |
No.1037 exhausted
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-24 22:10:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,349 bytes |
| コンパイル時間 | 1,787 ms |
| コンパイル使用メモリ | 180,480 KB |
| 実行使用メモリ | 92,416 KB |
| 最終ジャッジ日時 | 2024-10-15 02:58:07 |
| 合計ジャッジ時間 | 14,932 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, V, L; cin >> N >> V >> L;
vector<int> x(N), v(N); vector<long long> w(N);
for (int i = 0; i < N; i++) cin >> x[i] >> v[i] >> w[i];
x.emplace_back(L);
vector<vector<long long>> c(N+1, vector<long long>(V+1, 1e16));
if (V < x[0]) {
cout << -1 << "\n";
return 0;
}
c[0][V-x[0]] = 0;
set<array<long long, 3>> s;
s.insert({c[0][V-x[0]], 0, V-x[0]});
while (!s.empty()) {
auto it = *s.begin();
s.erase(s.begin());
if (it[0] != c[it[1]][it[2]]) continue;
if (it[1] == N) continue;
auto i = it[1];
auto vi = it[2];
if (vi < V) {
int p = min((int)vi+v[i], V);
if (c[i][p] > it[0] + w[i]) {
c[i][p] = it[0] + w[i];
s.insert({c[i][p], i, p});
}
}
if (vi >= x[i+1] - x[i]) {
if (c[i+1][vi-(x[i+1]-x[i])] > it[0]) {
c[i+1][vi-(x[i+1]-x[i])] = it[0];
s.insert({it[0], i+1, vi-(x[i+1]-x[i])});
}
}
}
long long ans = 1e16;
for (int i = 0; i <= V; i++) {
ans = min(ans, c[N][i]);
}
ans = ans == 1e16 ? -1 : ans;
cout << ans << "\n";
return 0;
}