結果

問題 No.1947 質より種類数
ユーザー tnakao0123tnakao0123
提出日時 2022-05-21 02:39:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,283 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 43,436 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 15:30:27
合計ジャッジ時間 1,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 17 ms
4,348 KB
testcase_11 AC 19 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 17 ms
4,348 KB
testcase_14 AC 26 ms
4,348 KB
testcase_15 AC 20 ms
4,348 KB
testcase_16 AC 27 ms
4,348 KB
testcase_17 AC 31 ms
4,348 KB
testcase_18 AC 37 ms
4,348 KB
testcase_19 AC 35 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 33 ms
4,348 KB
testcase_22 AC 17 ms
4,348 KB
testcase_23 AC 24 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 38 ms
4,348 KB
testcase_30 AC 60 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 59 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1947.cc:  No.1947 質より種類数 - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 5000;
const int MAX_V = 5000;

/* typedef */

typedef long long ll;

/* global variables */

int vs[MAX_N], ws[MAX_N], vws[MAX_V + 1];
ll dp[2][MAX_V + 1];

/* subroutines */

template <typename T>
inline void setmax(T &a, T b) { if (a < b) a = b; }

/* main */

int main() {
  int n, v, c;
  scanf("%d%d%d", &n, &v, &c);
  for (int i = 0; i < n; i++) scanf("%d%d", vs + i, ws + i);

  for (int i = 0; i < n; i++)
    if (vws[vs[i]] < ws[i])
      for (int j = vs[i], w = ws[i]; j <= v; j += vs[i], w += ws[i])
	setmax(vws[j], w);
      
  fill(dp[0], dp[0] + v + 1, -1);
  dp[0][0] = 0;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n; i++) {
    int wi = c + ws[i];
    for (int j = v - vs[i]; j >= 0; j--)
      if (dp[cur][j] >= 0)
	setmax(dp[cur][j + vs[i]], dp[cur][j] + wi);
  }

  copy(dp[cur], dp[cur] + v + 1, dp[nxt]);

  for (int j = 0; j < v; j++)
    if (dp[cur][j] > 0)
      for (int k = 1; j + k <= v; k++)
	setmax(dp[nxt][j + k], dp[cur][j] + vws[k]);
  swap(cur, nxt);

  ll maxd = 0;
  for (int j = 0; j <= v; j++) setmax(maxd, dp[cur][j]);

  printf("%lld\n", maxd);
  return 0;
}
0