結果

問題 No.1037 exhausted
ユーザー potoooooooo
提出日時 2020-04-24 22:07:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,307 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 180,484 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-10-15 02:55:53
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#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) {
            if (c[i][V] > it[0] + w[i]) {
                c[i][V] = it[0] + w[i];
                s.insert({c[i][V], i, V});
            }
        }
        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;
}
0