結果

問題 No.1037 exhausted
ユーザー ngtkanangtkana
提出日時 2019-10-09 01:07:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 204,116 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-04 15:25:27
合計ジャッジ時間 3,318 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 14 ms
4,380 KB
testcase_19 AC 12 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};

void err() { std::cout << -1 << std::endl; exit(0); }
#define require(exp) do { if (!(exp)) { err(); } } while(false)

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, V, L;
  std::cin >> n >> V >> L;
  std::vector< int > x(n), v(n), w(n);
  rep(i, 0, n) {
    std::cin >> x.at(i) >> v.at(i) >> w.at(i);
  }
  x.push_back(L);
  v.push_back(0);
  w.push_back(0);

  // error
  if (V < x.front())
    { err(); }
  rep(i, 0, n) {
    if (V < x.at(i + 1) - x.at(i))
      { err(); }
  }

  constexpr lint linf = 1LL << 60;
  std::vector< lint > dp(V + L + 1, linf);
  dp.at(V) = 0;
  auto time = 0;
  rep(i, 0, n + 1) {
    auto s = x.at(i), t = s + V;
    for (auto j = t; j >= s; j--) {
      if (dp.at(j) == linf) continue;
      auto k = std::min(t, j + v.at(i));
      cmn(dp.at(k), dp.at(j) + w.at(i));
    }
  }
  auto ret = *std::min_element(dp.begin() + L, dp.end());
  if (ret == linf) err();
  std::cout << ret << std::endl;
  return 0;
}
0