結果

問題 No.2364 Knapsack Problem
ユーザー taigatappuritaigatappuri
提出日時 2023-06-30 23:35:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,490 bytes
コンパイル時間 3,317 ms
コンパイル使用メモリ 221,560 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 17:51:02
合計ジャッジ時間 4,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
using Graph = vector<vector<long long>>;
#define all(v) v.begin(), v.end()
#define inf 2147483647
#define INF 9223372036854775807
#define gcd(a, b) __gcd((a), (b))
#define ll long long
#define fi first
#define se second
#define mod107 1000000007
#define mod998 998244353;
#define eps 1e-9
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define SHOW(x) std::clog << #x ": " << (x) << std::endl
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
template <class T>
istream &operator>>(istream &s, vector<T> &v)
{
    for (auto &e : v)
        s >> e;
    return s;
}
template <class T>
ostream &operator<<(ostream &s, const vector<T> &v)
{
    for (auto &e : v)
        s << e << ' ';
    return s;
}
template <class T, class U>
ostream &operator<<(ostream &s, const pair<T, U> &p)
{
    s << p.first << ' ' << p.second;
    return s;
}

int dx[8] = {-1, 0, 1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

struct edge
{
    ll to, cost;
};
ll lcm(ll a, ll b)
{ // オーバーフローしない
    return a / __gcd(a, b) * b;
}



int main()
{   ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N,M,W;
    cin >> N >> M >> W;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(M);
    vector<int> D(M);
    vector<int> E(N + M);
    vector<int> F(N + M);

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;

    for(int i = 0;i < N;i++){
        E[i] = A[i];
    }
    for(int i = 0;i < N;i++){
        F[i] = B[i];
    }

    for(int i = 0;i < M;i++){
        E[i + N] = C[i];
    }
    for(int i = 0;i < M;i++){
        F[i + N] = D[i];
    }

    ll ans = 0;
    ll nm = N + M;
    for(int bit = 0;bit < (1 << nm);bit++){
        ll w = 0;
        ll pre = 0;
        for(int i = 0;i < nm;i++){
            if(bit & (1 << i)){
                if(i < N){
                    w += E[i];
                    pre += F[i];
                }
                else{
                    w -= E[i];
                    pre -= F[i];
                }
            }
        }
        if(w <= W){
            ans = max(ans,pre);
        }
    }
    cout << ans << endl;
}
0