結果

問題 No.2364 Knapsack Problem
ユーザー as277575as277575
提出日時 2023-06-30 21:59:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,360 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 123,000 KB
実行使用メモリ 68,024 KB
最終ジャッジ日時 2023-09-21 15:56:39
合計ジャッジ時間 4,001 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
4,944 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 17 ms
8,652 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 6 ms
5,020 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 166 ms
67,652 KB
testcase_13 AC 160 ms
67,776 KB
testcase_14 WA -
testcase_15 AC 177 ms
67,700 KB
testcase_16 AC 166 ms
67,688 KB
testcase_17 AC 173 ms
67,788 KB
testcase_18 AC 161 ms
68,024 KB
testcase_19 AC 169 ms
67,796 KB
testcase_20 AC 170 ms
67,852 KB
testcase_21 AC 158 ms
67,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bit>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <set>
#include <string>

using namespace::std;

template <typename T>
void print(const T& v) {
 for (const auto& x : v) cout << x << " ";
 cout << endl;
}

int main() {
  ios::sync_with_stdio(false);
   long long n, m, w;
  cin >> n >> m >> w;
  vector< long long> dw(n + m);
  for ( long long i = 0ll; i < n; ++i) cin >> dw[i];
  vector< long long> dv(n + m);
  for ( long long i = 0ll; i < n; ++i) cin >> dv[i];
  for ( long long i = 0ll; i < m; ++i) { cin >> dw[n + i]; dw[n + i] = -dw[n + i]; }
  for ( long long i = 0ll; i < m; ++i) { cin >> dv[n + i]; dv[n + i] = -dv[n + i]; }
  
  vector<vector<long long>> d(1ll << (n + m), vector<long long>(w + 1ll));
  
  long long r = 0ll;
  for ( long long s = 1ll; s < 1ll << (n + m); ++s)
    for ( long long i = 0ll; i < n + m; ++i)
      if (s & (1ll << i))
        for ( long long pw = 0ll; pw <= w; ++pw) {
           long long nw = pw + dw[i];
          if (0ll <= nw && nw <= w) {
            d[s][nw] = max(d[s][nw], d[s ^ (1ll << i)][pw] + dv[i]);   
            r = max(r, d[s][nw]);
          }
        }
  
  cout << r << endl;

  return 0;
}

0