Submission #519639

# Submission time Handle Problem Language Result Execution time Memory
519639 2022-01-26T21:05:01 Z K4YAN Kitchen (BOI19_kitchen) C++17
20 / 100
15 ms 1624 KB
//Be Name Khoda

#include<bits/stdc++.h>
#pragma GCC optmize("Ofast,unroll-loops")
#pragma GCC target ("avx2,tune=native")

using namespace std;

#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<pll, ll>

const int mxn = 316;
ll n, m, k, q, w;
int mx[mxn * mxn];
vector<ll> a, b, g, f, A;
vector<pll> v;
bitset<mxn * mxn> dp, pd;

void input() {

    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) {
        cin >> q;
        a.push_back(q);
        w += q;
    }
    for(int i = 0; i < m; i++) {
        cin >> q;
        b.push_back(q);
        if(q <= n) {
            g.push_back(q);
        } else {
            f.push_back(q);
        }
    }

}

void solve() {

    if(m < k) {
        cout << "Impossible\n";
        return;
    }
    for(auto u : a) {
        if(u < k) {
            cout << "Impossible\n";
            return;
        }
    }
    dp.set(0);
    for(auto u : g) {
        dp |= (dp << u);
    }
    pd.set(0);
    for(auto u : f) {
        for(int i = mxn * mxn - 1; i > u - 1; i--) {
            if(pd[i - u]) {
                pd.set(i);
                mx[i] = max(mx[i - u] + 1, mx[i]);
            }
        }
    }
    for(int i = 0; i < mxn * mxn; i++) {
        if(pd[i]) {
            v.push_back({mx[i], i});
        }
    }
    for(int i = 0; i < mxn * mxn; i = dp._Find_next(i)) {
        A.push_back(i);
    }
    sort(all(v));
    ll ans = mxn * mxn, sum = 0, ptr;
    for(int i = 0; i < int(v.size()); i++) {
        ptr = lower_bound(all(A), max(0LL, max(w - v[i].second, (n - v[i].first) * k))) - A.begin();
        if(ptr < int(A.size())) {
            sum = A[ptr] + v[i].second;
            ans = min(ans, sum - w);
        }
    }
    if(ans == mxn * mxn) {
        cout << "Impossible\n";
        return;
    }
    cout << ans << endl;

}

int main() {

    ios::sync_with_stdio(false); cin.tie(NULL);

    input(), solve();   

    return 0;

}

Compilation message

kitchen.cpp:4: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
    4 | #pragma GCC optmize("Ofast,unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 720 KB Output is correct
2 Correct 2 ms 972 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 15 ms 1624 KB Output is correct
5 Correct 2 ms 1452 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -