結果

問題 No.2364 Knapsack Problem
ユーザー shogo314shogo314
提出日時 2023-06-30 21:42:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,399 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 211,964 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 09:22:20
合計ジャッジ時間 10,821 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 91 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 23 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 713 ms
5,376 KB
testcase_13 AC 621 ms
5,376 KB
testcase_14 AC 534 ms
5,376 KB
testcase_15 AC 922 ms
5,376 KB
testcase_16 AC 604 ms
5,376 KB
testcase_17 AC 790 ms
5,376 KB
testcase_18 AC 637 ms
5,376 KB
testcase_19 AC 1,091 ms
6,944 KB
testcase_20 AC 1,082 ms
6,944 KB
testcase_21 AC 659 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

using ll = long long;
using str = string;
using pl = pair<ll, ll>;
template <typename T>
using ml = map<ll, T>;
using mll = ml<ll>;
using sl = set<ll>;
using dbl = double;
using pd = pair<dbl, dbl>;
template <typename T>
using vec = vector<T>;
template <typename T>
using vv = vec<vec<T>>;
template <typename T1, typename T2>
using vp = vec<pair<T1, T2>>;
using vl = vec<ll>;
using vvl = vec<vl>;
using vs = vec<str>;
using vc = vec<char>;
using vpl = vec<pl>;
using vd = vec<dbl>;
using vpd = vec<pd>;
using tl3 = tuple<ll, ll, ll>;

const double INF = std::numeric_limits<double>::infinity();

#define LL(x) \
    ll x;     \
    cin >> x;
#define STR(s) \
    str s;     \
    cin >> s;
#define VL(a, n) \
    vl a(n);     \
    cin >> a;

#define all(obj) (obj).begin(), (obj).end()

#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repds(i, a, n) for (ll i = (n - 1); i >= (a); i--)
#define repd(i, n) repds(i, 0, n)
#define rrepd(i, n) repds(i, 1, n + 1)
#define rep2(i, j, x, y) rep(i, x) rep(j, y)

template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << " " << p.second;
    return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 != (int)v.size() ? " " : "");
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
    os << vec<T>(s.begin(), s.end());
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &in : v) is >> in;
    return is;
}
void print() { cout << '\n'; }
template <typename T>
void print(const T &t) {
    cout << t << '\n';
}
template <typename Head, typename... Tail>
void print(const Head &head, const Tail &...tail) {
    cout << head << ' ';
    print(tail...);
}
void print_accurate(dbl x) {
    cout << scientific << setprecision(15) << x << '\n';
}

void repr_(const ll &x) { cerr << x; }
void repr_(const int &x) { cerr << x; }
void repr_(const dbl &x) { cerr << x; }
void repr_(const str &x) { cerr << x; }
void repr_(const char &x) { cerr << x; }
void repr_(const char *x) { cerr << x; }
template <typename T1, typename T2>
void repr_(const pair<T1, T2> &p);
template <typename T1, typename T2>
void repr_(const map<T1, T2> &m);
template <typename T>
void repr_(const vec<T> &v);
template <typename T>
void repr_(const set<T> &s);
template <typename T1, typename T2>
void repr_(const pair<T1, T2> &p) {
    cerr << '(';
    repr_(p.first);
    cerr << ", ";
    repr_(p.second);
    cerr << ')';
}
template <typename T>
void repr_(const vec<T> &v) {
    cerr << '[';
    for (int i = 0; i < (int)v.size(); i++) {
        repr_(v[i]);
        if (i + 1 != (int)v.size()) cerr << ", ";
    }
    cerr << ']';
}
template <typename T>
void repr_(const set<T> &s) {
    cerr << '{';
    vec<T> v = vec<T>(all(s));
    for (int i = 0; i < (int)v.size(); i++) {
        repr_(v[i]);
        if (i + 1 != (int)v.size()) cerr << ", ";
    }
    cerr << '}';
}
template <typename T1, typename T2>
void repr_(const map<T1, T2> &m) {
    cerr << '{';
    vp<T1, T2> v = vp<T1, T2>(all(m));
    for (int i = 0; i < (int)v.size(); i++) {
        repr_(v[i].first);
        cerr << ": ";
        repr_(v[i].second);
        if (i + 1 != (int)v.size()) cerr << ", ";
    }
    cerr << '}';
}
template <typename Head, typename... Tail>
void repr_(const Head &head, const Tail &...tail) {
    repr_(head);
    repr_(' ');
    repr_(tail...);
}
template <typename T>
void repr(const T &t) {
    repr_(t);
    cerr << '\n';
}
template <typename Head, typename... Tail>
void repr(const Head &head, const Tail &...tail) {
    repr_(head);
    repr_(' ');
    repr(tail...);
}

void solve() {
    ll N, M, W;
    cin >> N >> M >> W;
    vl A(N), B(N), C(M), D(M);
    cin >> A >> B >> C >> D;
    vl s, t;
    ll ans = 0;
    rep(i, N) {
        s.push_back(i);
    }
    rep(i, M) {
        t.push_back(i);
    }
    while (next_permutation(all(s))) {
        while (next_permutation(all(t))) {
            ll i, j, w, v;
            i = j = w = v = 0;
            while (1) {
                if (i < N && w + A.at(s.at(i)) <= W) {
                    w += A.at(s.at(i));
                    v += B.at(s.at(i));
                    chmax(ans, v);
                    i++;
                    continue;
                }
                if (j < M && w - C.at(t.at(j)) >= 0) {
                    w -= C.at(t.at(j));
                    v -= D.at(t.at(j));
                    j++;
                    continue;
                }
                break;
            }
        }
    }
    print(ans);
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
0