結果

問題 No.1037 exhausted
ユーザー tnakao0123tnakao0123
提出日時 2020-04-25 16:30:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 91,644 KB
実行使用メモリ 35,000 KB
最終ジャッジ日時 2023-08-07 03:49:25
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 25 ms
34,728 KB
testcase_13 AC 25 ms
34,836 KB
testcase_14 AC 26 ms
34,720 KB
testcase_15 AC 25 ms
34,748 KB
testcase_16 AC 26 ms
34,724 KB
testcase_17 AC 26 ms
34,800 KB
testcase_18 AC 27 ms
34,700 KB
testcase_19 AC 27 ms
34,668 KB
testcase_20 AC 17 ms
34,728 KB
testcase_21 AC 17 ms
34,840 KB
testcase_22 AC 17 ms
35,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1037.cc:  No.1037 exhausted - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000;
const int MAX_V = 2000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

int xs[MAX_N + 2], vs[MAX_N + 1], wis[MAX_N + 1];
ll dp[MAX_N + 2][MAX_V + 1];

/* subroutines */

inline void setmin(ll &a, ll b) { if (a > b) a = b; }

/* main */

int main() {
  int n, v, l;
  scanf("%d%d%d", &n, &v, &l);

  for (int i = 1; i <= n; i++)
    scanf("%d%d%d", xs + i, vs + i, wis + i);
  xs[0] = vs[0] = wis[0] = 0;
  xs[n + 1] = l;

  for (int i = 0; i <= n + 1; i++) fill(dp[i], dp[i] + v + 1, LINF);

  dp[0][v] = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= v; j++)
      if (dp[i][j] < LINF) {
	int l = xs[i + 1] - xs[i];

	if (j >= l) setmin(dp[i + 1][j - l], dp[i][j]);

	if (vs[i] > 0) {
	  int j1 = min(v, j + vs[i]);
	  if (j1 >= l) setmin(dp[i + 1][j1 - l], dp[i][j] + wis[i]);
	}
      }

  ll mind = LINF;
  for (int j = 0; j <= v; j++) setmin(mind, dp[n + 1][j]);

  printf("%lld\n", (mind >= LINF) ? -1LL : mind);
  return 0;
}
0