結果

問題 No.2741 Balanced Choice
ユーザー おぼおぼ
提出日時 2024-04-21 10:23:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,052 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 176,888 KB
実行使用メモリ 127,432 KB
最終ジャッジ日時 2024-04-21 10:23:13
合計ジャッジ時間 8,321 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(int)(b);i++)
#define ll long long

int main() {
    int n, W, D;
    cin>>n>>W>>D;

    vector<int> t(n),w(n),v(n);
    rep(i,0,n) {
        cin>>t[i]>>w[i]>>v[i];
    }

    vector<map<int,int>> dp(W+1);
    dp[0][0] = 0;

    rep(i,0,n) {
        for(int j=W;j>=w[i];j--) {
            vector<pair<int,int>> updates;
            for(auto &p:dp[j-w[i]]) {
                int new_diff = (t[i]==0) ? (p.first+w[i]) : (p.first-w[i]);
                updates.push_back({new_diff, p.second+v[i]});
            }
            for(auto &u:updates) {
                if(dp[j].find(u.first)==dp[j].end()||dp[j][u.first]<u.second) {
                    dp[j][u.first]=u.second;
                }
            }
        }
    }

    int max_value = 0;
    // rep(j,0,W+1) {
    //     for(auto &p:dp[j]) {
    //         if(abs(p.first)<=D) {
    //             max_value=max(max_value,p.second);
    //         }
    //     }
    // }

    cout<<max_value<<endl;
    return 0;
}
0