結果

問題 No.1037 exhausted
ユーザー risujirohrisujiroh
提出日時 2020-04-24 22:07:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 205,956 KB
実行使用メモリ 34,528 KB
最終ジャッジ日時 2023-08-05 05:05:28
合計ジャッジ時間 3,444 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 37 ms
34,448 KB
testcase_13 AC 37 ms
34,136 KB
testcase_14 AC 36 ms
34,144 KB
testcase_15 AC 37 ms
34,448 KB
testcase_16 AC 37 ms
34,204 KB
testcase_17 AC 36 ms
34,404 KB
testcase_18 AC 36 ms
34,528 KB
testcase_19 AC 37 ms
34,140 KB
testcase_20 AC 36 ms
34,184 KB
testcase_21 AC 34 ms
34,456 KB
testcase_22 AC 32 ms
34,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; };

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, l;
  cin >> n >> m >> l;
  vector<int> x{0}, v{m}, w{0};
  for (int i = 0; i < n; ++i) {
    int xi, vi, wi;
    cin >> xi >> vi >> wi;
    if (xi == 0 or xi == l) {
      continue;
    }
    x.push_back(xi);
    v.push_back(vi);
    w.push_back(wi);
  }
  n = size(x);
  DEBUG(x);
  x.push_back(l);
  vector dp(n + 1, vector(m + 1, inf<long long>));
  fill(begin(dp[n]), end(dp[n]), 0);
  for (int i = n; i--; ) {
    for (int r = 0; r <= m; ++r) {
      if (x[i + 1] - x[i] <= r) {
        chmin(dp[i][r], dp[i + 1][r - (x[i + 1] - x[i])]);
      }
      if (int nr = min(r + v[i], m) - (x[i + 1] - x[i]); nr >= 0) {
        chmin(dp[i][r], w[i] + dp[i + 1][nr]);
      }
    }
  }
  if (dp[0][m] >= inf<long long>) {
    dp[0][m] = -1;
  }
  cout << dp[0][m] << '\n';
}
0