結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2020-04-24 22:39:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 850 bytes |
コンパイル時間 | 1,562 ms |
コンパイル使用メモリ | 166,200 KB |
実行使用メモリ | 35,212 KB |
最終ジャッジ日時 | 2024-10-15 03:15:11 |
合計ジャッジ時間 | 3,198 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long longtemplate<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }const int inf = 3000ll*1000000000ll;int n, V, l;int x[2010];int v[2010];int w[2010];int memo[2010][2010];int dp(int i, int noko){if(noko < 0) return inf;if(i == n) return 0;if(memo[i][noko] != -1) return memo[i][noko];return memo[i][noko] = min(dp(i+1, noko-(x[i+1]-x[i])),dp(i+1, min(noko+v[i], V)-(x[i+1]-x[i]))+w[i]);}signed main(){cin >> n >> V >> l;for(int i = 0;i < n;i++){cin >> x[i] >> v[i] >> w[i];}x[n] = l;memset(memo, -1, sizeof(memo));int ans = dp(0, V-x[0]);if(ans < inf){cout << ans << endl;}else{cout << -1 << endl;}return 0;}