結果

問題 No.1037 exhausted
ユーザー potoooooooopotoooooooo
提出日時 2020-04-24 22:10:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,349 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 175,908 KB
実行使用メモリ 92,544 KB
最終ジャッジ日時 2024-04-23 03:25:26
合計ジャッジ時間 15,555 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 1 ms
6,940 KB
testcase_11 WA -
testcase_12 AC 1,412 ms
77,824 KB
testcase_13 AC 1,060 ms
64,128 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1,910 ms
92,544 KB
testcase_17 AC 1,643 ms
86,272 KB
testcase_18 AC 1,767 ms
85,888 KB
testcase_19 WA -
testcase_20 AC 29 ms
34,560 KB
testcase_21 AC 26 ms
34,560 KB
testcase_22 AC 26 ms
34,688 KB
権限があれば一括ダウンロードができます

ソースコード

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) {
            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;
}
0