結果

問題 No.1037 exhausted
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-09 22:04:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 199,428 KB
実行使用メモリ 35,212 KB
最終ジャッジ日時 2023-08-30 23:14:41
合計ジャッジ時間 3,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,992 KB
testcase_01 AC 11 ms
34,996 KB
testcase_02 AC 12 ms
34,944 KB
testcase_03 AC 11 ms
34,916 KB
testcase_04 AC 11 ms
35,040 KB
testcase_05 AC 11 ms
34,944 KB
testcase_06 AC 11 ms
35,116 KB
testcase_07 AC 11 ms
34,948 KB
testcase_08 AC 11 ms
35,212 KB
testcase_09 AC 12 ms
34,920 KB
testcase_10 AC 11 ms
35,048 KB
testcase_11 AC 12 ms
35,212 KB
testcase_12 AC 26 ms
35,012 KB
testcase_13 AC 24 ms
34,960 KB
testcase_14 AC 26 ms
35,060 KB
testcase_15 AC 27 ms
35,068 KB
testcase_16 AC 27 ms
35,060 KB
testcase_17 AC 24 ms
34,940 KB
testcase_18 AC 25 ms
34,940 KB
testcase_19 AC 26 ms
35,152 KB
testcase_20 AC 21 ms
34,940 KB
testcase_21 AC 21 ms
34,932 KB
testcase_22 AC 19 ms
34,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int N, V, L, x[2010], v[2010], w[2010];
ll dp[2010][2010];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> N >> V >> L;
  REP(i, 1, N+1) cin >> x[i] >> v[i] >> w[i];
  x[0] = w[0] = 0;
  v[0] = V;
  x[N+1] = L;
  rep(i, 2010) rep(j, 2010) dp[i][j] = (1LL<<60);
  dp[0][0] = 0;
  rep(i, N+1) rep(j, V+1) {
    if(min(V, j+v[i])-(x[i+1]-x[i]) >= 0) chmin(dp[i+1][min(V, j+v[i])-(x[i+1]-x[i])], dp[i][j]+w[i]);
    if(j-(x[i+1]-x[i]) >= 0) chmin(dp[i+1][j-(x[i+1]-x[i])], dp[i][j]);
  }
  ll ans = (1LL<<60);
  rep(j, V+1) {
    chmin(ans, dp[N+1][j]);
  }
  if(ans == (1LL<<60)) ans = -1;
  cout << ans << '\n';
  return 0;
}
0