結果

問題 No.2364 Knapsack Problem
ユーザー UMRgurashiUMRgurashi
提出日時 2023-06-30 21:38:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,322 bytes
コンパイル時間 3,134 ms
コンパイル使用メモリ 217,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 15:31:15
合計ジャッジ時間 3,799 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:22: 警告: overflow in conversion from ‘long long int’ to ‘int’ changes value from ‘2305843009213693952’ to ‘0’ [-Woverflow]
   11 | const  int INF = 1LL << 61;
      |                  ~~~~^~~~~

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
#define endl "\n"
using std::abs;

using namespace std;
const  int INF = 1LL << 61;
#define int long long
#define double long double
#define stoi stoll


#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,n) for(int i=1;i<=n;i++)
#define sREP(i,n) for(int i=1;i*i<=n;++i)
#define krep(i,k,n) for(int i=(k);i<n+k;i++)
#define Krep(i,k,n) for(int i=(k);i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Rrep(i,n) for(int i=n;i>0;i--)
#define frep(i,n) for(auto &x:n)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x)
#define RUD(a,b) (((a)+(b)-1)/(b))
#define sum1_n(n) ((n)*(n+1)/2)
#define SUM1n2(n) (n*(2*n+1)*(n+1))/6
#define SUMkn(k,n) (SUM1n(n)-SUM1n(k-1))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define Fi first
#define Se second
#define lower(vec, i) *lower_bound(ALL(vec), i)
#define upper(vec, i) *upper_bound(ALL(vec), i)
#define lower_count(vec, i) (int)(lower_bound(ALL(vec), i) - (vec).begin())
#define acc(vec) accumulate(ALL(vec),0LL)
template<class... T>
constexpr auto min(T... a) {
    return min(initializer_list<common_type_t<T...>>{a...});
}

template<class... T>
constexpr auto max(T... a) {
    return max(initializer_list<common_type_t<T...>>{a...});
}

template<class... T>
void in(T&... a) {
    (cin >> ... >> a);
}


void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T& t, const U &...u) {
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}


#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
string ins() { string x; cin >> x; return x; }

template <class T>
using v = vector<T>;
template <class T>
using vv = vector<v<T>>;
template <class T>
using vvv = vector<vv<T>>;

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using qint = tuple<int, int, int, int>;

inline bool BETWEEN(int x, int min, int max) {
    if (min <= x && x <= max)
        return true;
    else
        return false;
}
inline bool between(int x, int min, int max) {
    if (min < x && x < max) return true;
    else return false;
}
template<class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

inline bool bit(int x, int i) {
    return x >> i & 1;
}


void solve() {
    int N, M, W;
    cin >> N >> M >> W;
    int n = N + M;
    v<int> v(n), w(n);
    rep(i, N)cin >> w[i];
    rep(i, N)cin >> v[i];
    rep(i, M) {
        cin >> w[N + i];
        w[N + i] *= -1;
    }
    rep(i, M) {
        cin >> v[N + i];
        v[N + i] *= -1;
    }
    int ans = 0;
    rep(i, (1LL << n)) {
        int nv = 0, nw = 0;
        rep(j, n) {
            if (bit(i, j)&&BETWEEN(w[j],-W,W)) {
                nv += v[j];
                nw += w[j];
            }
        }
        if (0 <= nw && nw <= W)chmax(ans, nv);
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //cout << setfill('0') << right << setw(3);
    solve();
}
0