結果

問題 No.2364 Knapsack Problem
ユーザー as277575as277575
提出日時 2023-06-30 21:52:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 124,568 KB
実行使用メモリ 67,852 KB
最終ジャッジ日時 2023-09-21 15:48:34
合計ジャッジ時間 3,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 5 ms
4,960 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 13 ms
8,716 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 5 ms
4,836 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 133 ms
67,720 KB
testcase_13 AC 133 ms
67,668 KB
testcase_14 WA -
testcase_15 AC 137 ms
67,848 KB
testcase_16 AC 131 ms
67,708 KB
testcase_17 AC 133 ms
67,708 KB
testcase_18 AC 129 ms
67,844 KB
testcase_19 AC 138 ms
67,792 KB
testcase_20 AC 139 ms
67,672 KB
testcase_21 AC 130 ms
67,852 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);
  int n, m, w;
  cin >> n >> m >> w;
  vector<int> dw(n + m);
  for (int i = 0; i < n; ++i) cin >> dw[i];
  vector<int> dv(n + m);
  for (int i = 0; i < n; ++i) cin >> dv[i];
  for (int i = 0; i < m; ++i) { cin >> dw[n + i]; dw[n + i] = -dw[n + i]; }
  for (int i = 0; i < m; ++i) { cin >> dv[n + i]; dv[n + i] = -dv[n + i]; }
  
  vector<vector<long long>> d(1 << (n + m), vector<long long>(w + 1));
  
  long long r = 0;
  for (int s = 1; s < 1 << (n + m); ++s)
    for (int i = 0; i < n + m; ++i)
      if (s & (1 << i))
        for (int pw = 0; pw <= w; ++pw) {
          int nw = pw + dw[i];
          if (0 <= nw && nw <= w) {
            d[s][nw] = max(d[s][nw], d[s ^ (1 << i)][pw] + dv[i]);   
            r = max(r, d[s][nw]);
          }
        }
  
  cout << r << endl;

  return 0;
}

0