結果

問題 No.2364 Knapsack Problem
ユーザー 👑 NachiaNachia
提出日時 2023-06-30 22:49:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 3,000 ms
コード長 1,181 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 80,228 KB
実行使用メモリ 35,252 KB
最終ジャッジ日時 2023-09-21 17:03:18
合計ジャッジ時間 2,224 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 6 ms
5,912 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 6 ms
6,644 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 53 ms
35,104 KB
testcase_13 AC 56 ms
35,076 KB
testcase_14 AC 59 ms
35,156 KB
testcase_15 AC 55 ms
35,188 KB
testcase_16 AC 75 ms
35,252 KB
testcase_17 AC 76 ms
34,996 KB
testcase_18 AC 63 ms
35,060 KB
testcase_19 AC 65 ms
35,116 KB
testcase_20 AC 69 ms
35,000 KB
testcase_21 AC 62 ms
35,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;


void chmax(int& a, int b){ if(a < b) a = b; }

int main(){
    int N, M, W; cin >> N >> M >> W;
    vector<int> dp((W+1)<<(N+M), -1001001001);
    vector<int> A(N); rep(i,N) cin >> A[i];
    vector<int> B(N); rep(i,N) cin >> B[i];
    vector<int> C(M); rep(i,M) cin >> C[i];
    vector<int> D(M); rep(i,M) cin >> D[i];
    dp[0] = 0;
    rep(n,1<<N) rep(m,1<<M) rep(w,W+1){
        int val = dp[w<<(N+M) | n<<M | m];
        if(val < -501001001) continue;
        rep(i,N) if(w+A[i] <= W) if(!(n & (1<<i))){
            chmax(dp[(w+A[i])<<(N+M) | n<<M | m | 1<<(i+M)], val + B[i]);
        }
        rep(i,M) if(w-C[i] >= 0) if(!(m & (1<<i))){
            chmax(dp[(w-C[i])<<(N+M) | n<<M | m | 1<<i], val - D[i]);
        }
    }
    int ans = *max_element(dp.begin(), dp.end());
    cout << ans << endl;
    return 0;
}
0