結果

問題 No.1037 exhausted
ユーザー KoDKoD
提出日時 2020-04-24 21:50:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 2,633 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 83,672 KB
実行使用メモリ 34,528 KB
最終ジャッジ日時 2023-08-05 04:51:04
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 37 ms
34,472 KB
testcase_13 AC 38 ms
34,456 KB
testcase_14 AC 37 ms
34,200 KB
testcase_15 AC 37 ms
34,144 KB
testcase_16 AC 37 ms
34,252 KB
testcase_17 AC 38 ms
34,504 KB
testcase_18 AC 38 ms
34,196 KB
testcase_19 AC 37 ms
34,188 KB
testcase_20 AC 37 ms
34,320 KB
testcase_21 AC 36 ms
34,508 KB
testcase_22 AC 35 ms
34,528 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:80:36: 警告: narrowing conversion of ‘(N + 2)’ from ‘int’ to ‘std::size_t’ {aka ‘long unsigned int’} [-Wnarrowing]
   80 |   auto dp = gen_vec<long long>({ N + 2, V + 1 }, inf);
      |                                  ~~^~~
main.cpp:80:43: 警告: narrowing conversion of ‘(V + 1)’ from ‘int’ to ‘std::size_t’ {aka ‘long unsigned int’} [-Wnarrowing]
   80 |   auto dp = gen_vec<long long>({ N + 2, V + 1 }, inf);
      |                                         ~~^~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T, std::size_t N, std::size_t I = 0>
auto gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I == N), const T&>::type value = T()) { 
  return value; 
}

template <class T, std::size_t N, std::size_t I = 0>
auto gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I != N), const T&>::type value = T()) { 
  return std::vector<decltype(gen_vec<T, N, I + 1>(list, value))>(list[I], gen_vec<T, N, I + 1>(list, value)); 
}

constexpr long long inf = (1ll << 60);

int main() {
  int N, V, L;
  std::cin >> N >> V >> L;
  std::vector<int> x(N + 2), v(N + 1), w(N + 1);
  x.back() = L;
  for (int i: range(1, N + 1)) {
    std::cin >> x[i] >> v[i] >> w[i];
  }
  std::vector<int> c(N + 1);
  for (int i: range(0, N + 1)) {
    c[i] = x[i + 1] - x[i];
  }
  auto dp = gen_vec<long long>({ N + 2, V + 1 }, inf);
  dp[0][V] = 0;
  for (int i: range(0, N + 1)) {
    for (int j: range(0, V + 1)) {
      {
        int nj = std::min(V, j + v[i]) - c[i];
        if (nj >= 0) {
          chmin(dp[i + 1][nj], dp[i][j] + w[i]);
        }
      }
      {
        int nj = j - c[i];
        if (nj >= 0) {
          chmin(dp[i + 1][nj], dp[i][j]);
        }
      }
    }
  }
  long long ans = inf;
  for (int i: range(0, V + 1)) {
    chmin(ans, dp[N + 1][i]);
  }
  std::cout << (ans == inf ? -1 : ans) << '\n';
  return 0;
}
0