結果

問題 No.1947 質より種類数
ユーザー tnakao0123tnakao0123
提出日時 2022-05-20 23:48:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 951 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 42,872 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 14:43:41
合計ジャッジ時間 6,358 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 2 ms
4,348 KB
testcase_04 AC 16 ms
4,348 KB
testcase_05 AC 14 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 15 ms
4,348 KB
testcase_08 AC 18 ms
4,348 KB
testcase_09 AC 17 ms
4,348 KB
testcase_10 AC 12 ms
4,348 KB
testcase_11 AC 35 ms
4,348 KB
testcase_12 AC 26 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 56 ms
4,348 KB
testcase_15 AC 28 ms
4,348 KB
testcase_16 AC 83 ms
4,348 KB
testcase_17 AC 111 ms
4,348 KB
testcase_18 AC 191 ms
4,348 KB
testcase_19 AC 167 ms
4,348 KB
testcase_20 AC 129 ms
4,348 KB
testcase_21 AC 143 ms
4,348 KB
testcase_22 AC 10 ms
4,348 KB
testcase_23 AC 74 ms
4,348 KB
testcase_24 AC 47 ms
4,348 KB
testcase_25 AC 39 ms
4,348 KB
testcase_26 AC 19 ms
4,348 KB
testcase_27 AC 29 ms
4,348 KB
testcase_28 AC 44 ms
4,348 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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 */

ll dp[2][MAX_V + 1];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

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

  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 vi, wi;
    scanf("%d%d", &vi, &wi);

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

    for (int j = 0; j < v; j++)
      if (dp[cur][j] >= 0) {
	ll d = dp[cur][j] + c + wi;
	for (int k = j + vi; k <= v; k += vi, d += wi)
	  setmax(dp[nxt][k], d);
      }

    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