結果
問題 | No.2364 Knapsack Problem |
ユーザー |
|
提出日時 | 2023-06-30 21:39:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,498 ms / 3,000 ms |
コード長 | 3,947 bytes |
コンパイル時間 | 2,144 ms |
コンパイル使用メモリ | 206,128 KB |
最終ジャッジ日時 | 2025-02-15 03:37:40 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef __int128_t lll;typedef long double ld;typedef pair<ll, ll> pl;typedef tuple<ll, ll, ll> tt;typedef vector<ll> vl;typedef vector<vl> vvl;typedef vector<vvl> vvvl;typedef vector<double> vd;typedef vector<vd> vvd;typedef vector<vvd> vvvd;typedef vector<bool> vb;typedef vector<vb> vvb;typedef vector<vvb> vvvb;typedef vector<char> vc;typedef vector<vc> vvc;typedef vector<vvc> vvvc;typedef vector<pl> vp;typedef vector<tt> vt;typedef vector<string> vs;const ll INF = 1000000010;const ll INFL = INF * INF;const double MYPI = acos(-1);const ld epsilon = 1e-10;#define ovl(a, b, c, d, e, ...) e#define pb push_back#define eb emplace_back#define MP make_pair#define DEBUG(...) DEBUG_(#__VA_ARGS__, __VA_ARGS__)#define REP1(i, n) for (int i = 0; i < (n); i++)#define REP2(i, l, r) for (int i = (l); i < (r); i++)#define REP3(i, l, r, d) for (int i = (l); i < (r); i += (d))#define REP(...) ovl(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)#define RREP1(i, n) for (int i = (n)-1; i >= 0; i--)#define RREP2(i, l, r) for (int i = (r)-1; i >= (l); i--)#define RREP3(i, l, r, d) for (int i = (r)-1; i >= (l); i -= (d))#define RREP(...) ovl(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)#define EACH1(e, a) for (auto &e : a)#define EACH2(x, y, a) for (auto &[x, y] : a)#define EACH3(x, y, z, a) for (auto &[x, y, z] : a)#define EACH(...) ovl(__VA_ARGS__, EACH3, EACH2, EACH1)(__VA_ARGS__)#define ALL(x) begin(x), end(x)#define RALL(x) (x).rbegin(), (x).rend()#define sz(x) (ll) x.size()#define LB(a, x) (lower_bound(ALL(a), x) - a.begin())#define UB(a, x) (upper_bound(ALL(a), x) - a.begin())#define FLG(x, i) (((x) >> (i)) & 1)#define CNTBIT(x) __builtin_popcountll(x)#define TOPBIT(t) (t == 0 ? -1 : 63 - __builtin_clzll(t))#define IN(x, a, b) ((a) <= (x) && (x) < (b))template <typename T, typename... Ts>void OUT(const T &a, const Ts &...b) {cout << a;(cout << ... << (cout << " ", b));cout << endl;}template <typename T>void DEBUG_(string_view name, const T &a) {cout << name << ": " << a << endl;}template <typename T>void DEBUG_(string_view name, const vector<T> &a) {cout << name << ": ";REP(i, sz(a)) cout << a[i] << " ";cout << endl;}template <typename T1, typename T2>bool chmax(T1 &x, const T2 &y) {return x < y ? x = y, 1 : 0;}template <typename T1, typename T2>bool chmin(T1 &x, const T2 &y) {return x > y ? x = y, 1 : 0;}int main() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(16);int N, M, W;cin >> N >> M >> W;vl As(N + M);vl Bs(N + M);REP(i, N) cin >> As[i];REP(i, N) cin >> Bs[i];REP(i, M) {cin >> As[N + i];As[N + i] *= -1;}REP(i, M) {cin >> Bs[N + i];Bs[N + i] *= -1;}vp bits(1 << (N + M));REP(bit, 1 << (N + M)) {bits[bit] = {0, bit};REP(i, N + M) {if (bit & (1 << i)) bits[bit].first -= Bs[i];}}sort(ALL(bits));EACH2(val, bit, bits) {vl idxs;int weight = 0;REP(i, N + M) {if (bit & (1 << i)) {idxs.pb(i);weight += As[i];}}if (!IN(weight, 0, W + 1)) {continue;}vl Ps(idxs.size());iota(ALL(Ps), 0);bool ok = false;do {int w = 0;bool ok2 = true;EACH(i, Ps) {w += As[idxs[i]];if (!IN(w, 0, W + 1)) {ok2 = false;break;}}if (ok2) {ok = true;break;}} while (next_permutation(ALL(Ps)));if (ok) {OUT(-val);return 0;}}return 0;}