結果

問題 No.1037 exhausted
ユーザー seriru13seriru13
提出日時 2020-04-26 20:32:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,349 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 204,796 KB
実行使用メモリ 34,916 KB
最終ジャッジ日時 2023-08-11 14:41:11
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 37 ms
34,912 KB
testcase_13 AC 37 ms
34,512 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 37 ms
34,432 KB
testcase_17 AC 38 ms
34,804 KB
testcase_18 AC 37 ms
34,680 KB
testcase_19 WA -
testcase_20 AC 35 ms
34,480 KB
testcase_21 AC 34 ms
34,684 KB
testcase_22 AC 31 ms
34,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll N,V,L;
  cin >> N >> V >> L;
  vector<ll> x(N+1), v(N+1), w(N+1);
  x[0] = 0, v[0] = V, w[0] = 0;
  for (int i = 0; i < N; ++i) {
    cin >> x[i+1] >> v[i+1] >> w[i+1];
  }
  x.push_back(L);
  v.push_back(inf);
  w.push_back(inf);
  // dp(i,j) = 地点、残り燃料、最小のコスト
  vector<vector<ll>> dp(N+10, vector<ll>(V+10, inf));
  dp[0][V] = 0;
  for (int i = 1; i <= N+1; ++i) {
    ll dist = x[i] - x[i-1];
    for (int j = 0; j <= V; ++j) {
      if (dist + j <= V) {
        dp[i][j] = min(dp[i][j], dp[i-1][dist+j]);
        dp[i][min(j + v[i], V)] = min(dp[i][min(j + v[i], V)], dp[i][j] + w[i]);
      }
    }
  }

  ll ans = inf;
  for (auto itr : dp[N+1]) {
    chmin(ans, itr);
  }

  cout << ((ans == inf) ? -1 : ans) << endl;
}
0