結果

問題 No.1947 質より種類数
ユーザー ronnyaronnya
提出日時 2022-05-21 13:02:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 1,248 bytes
コンパイル時間 4,335 ms
コンパイル使用メモリ 208,088 KB
実行使用メモリ 394,516 KB
最終ジャッジ日時 2023-10-20 16:02:06
合計ジャッジ時間 8,662 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
5,380 KB
testcase_05 AC 3 ms
4,588 KB
testcase_06 AC 3 ms
4,852 KB
testcase_07 AC 4 ms
5,116 KB
testcase_08 AC 4 ms
5,380 KB
testcase_09 AC 11 ms
11,980 KB
testcase_10 AC 8 ms
9,340 KB
testcase_11 AC 24 ms
23,068 KB
testcase_12 AC 17 ms
16,732 KB
testcase_13 AC 7 ms
8,020 KB
testcase_14 AC 118 ms
112,564 KB
testcase_15 AC 61 ms
58,708 KB
testcase_16 AC 170 ms
162,724 KB
testcase_17 AC 221 ms
210,508 KB
testcase_18 AC 403 ms
373,592 KB
testcase_19 AC 352 ms
326,668 KB
testcase_20 AC 266 ms
245,620 KB
testcase_21 AC 310 ms
289,444 KB
testcase_22 AC 19 ms
19,108 KB
testcase_23 AC 142 ms
131,044 KB
testcase_24 AC 5 ms
6,172 KB
testcase_25 AC 4 ms
5,380 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,852 KB
testcase_28 AC 4 ms
5,380 KB
testcase_29 AC 450 ms
394,516 KB
testcase_30 AC 454 ms
394,516 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 396 ms
394,516 KB
testcase_35 AC 396 ms
394,516 KB
testcase_36 AC 457 ms
394,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
#define irep(i, v) for(auto i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()

const ll INF = 3e18;
const ld EPS = 1e-10;
const ll MOD = 1e9 + 7;
const ld PI = M_PI;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  cout << fixed << setprecision(20);

  ll n, vmax, c;
  cin >> n >> vmax >> c;
  vector<ll> v(2 * n), w(2 * n);
  rep(i, 0, n){
    cin >> v[2 * i + 1] >> w[2 * i + 1];
    v[2 * i] = v[2 * i + 1];
    w[2 * i] = w[2 * i + 1] + c;
  }

  vector<vector<ll>> dp(2 * n + 1, vector<ll>(vmax + 1, 0));

  rep(i, 0, 2 * n){
    rep(j, 1, vmax + 1){
      if(i % 2 == 1){
        if(j - v[i] >= 0) dp[i + 1][j] = max({dp[i][j], dp[i + 1][j - v[i]] + w[i], dp[i + 1][j - 1]});
        else dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - 1]);
      }
      else{
        if(j - v[i] >= 0) dp[i + 1][j] = max({dp[i][j], dp[i][j - v[i]] + w[i], dp[i + 1][j - 1]});
        else dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      }
    }
  }

  cout << *max_element(ALL(dp[2 * n])) << endl;

  return 0;
}
0