結果

問題 No.2741 Balanced Choice
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2024-04-20 21:13:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,129 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 170,104 KB
実行使用メモリ 104,504 KB
最終ジャッジ日時 2024-04-20 21:14:02
合計ジャッジ時間 3,263 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
102,876 KB
testcase_01 AC 107 ms
104,504 KB
testcase_02 AC 114 ms
103,316 KB
testcase_03 AC 108 ms
104,492 KB
testcase_04 AC 108 ms
102,200 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 70 ms
104,416 KB
testcase_08 AC 91 ms
103,364 KB
testcase_09 AC 67 ms
103,120 KB
testcase_10 AC 75 ms
103,528 KB
testcase_11 AC 95 ms
103,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/



int N, W, D;
int t[5010], w[5010], v[5010];

const int BASE = 10101;
int dp[5010][10010];

vector<int> doDP(vector<pair<int,int>> wv) {
    int n = wv.size();
    rep(i, 0, n + 1) rep(w, 0, W + 1) dp[i][w] = -inf;
    dp[0][0] = 0;

    rep(i, 0, n) rep(w, 0, W + 1) {
        chmax(dp[i + 1][w], dp[i][w]);
        chmax(dp[i + 1][w + wv[i].first], dp[i][w] + wv[i].second);
    }

    vector<int> res(W + 1);
    rep(w, 0, W + 1) res[w] = dp[n][w];
    return res;
}

void _main() {
    cin >> N >> W >> D;
    vector<pair<int,int>> wv[2];
    rep(i, 0, N) {
        cin >> t[i] >> w[i] >> v[i];
        wv[t[i]].push_back({w[i], v[i]});
    }

    auto dp0 = doDP(wv[0]);
    auto dp1 = doDP(wv[1]);

    int ans = -inf;
    rep(w0, 0, W + 1) rep(w1, 0, W + 1) if(w0 + w1 <= W && abs(w0 - w1) <= D) chmax(ans, dp0[w0] + dp1[w1]);
    cout << ans << endl;
}





/*
## 前提知識
## 解法


*/
0