結果

問題 No.2364 Knapsack Problem
ユーザー hiro71687khiro71687k
提出日時 2023-07-05 17:03:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,298 bytes
コンパイル時間 4,216 ms
コンパイル使用メモリ 260,780 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 17:18:58
合計ジャッジ時間 5,357 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=9999999999999999;
ll mod=998244353;
int main(){
    ll n,m,w;
    cin >> n >> m >> w;
    vector<ll>a(n),b(n),c(m),d(m);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (ll i = 0; i < m; i++)
    {
        cin >> c[i];
    }
    for (ll i = 0; i < m; i++)
    {
        cin >> d[i];
    }
    vector<ll>two(10,1);
    ll ans=0;
    for (ll i = 1; i < 10; i++)
    {
        two[i]=two[i-1]*2;
    }
    for (ll i = 0; i < two[n]; i++)
    {
        for (ll j = 0; j < two[m]; j++)
        {
            ll x=0,y=0;
            for (ll k = 0; k < n; k++)
            {
                if (two[k]&i)
                {
                    x+=a[k];
                    y+=b[k];
                }
            }
            for (ll k = 0; k < m; k++)
            {
                if (two[k]&j)
                {
                    x-=c[k];
                    y-=d[k];
                }
            }
            if (x>w)
            {
                continue;
            }
            ans=max(ans,y);
        }
    }
    cout << ans << endl;
}
0