답안 #519638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519638 2022-01-26T21:03:00 Z K4YAN Kitchen (BOI19_kitchen) C++17
0 / 100
4 ms 968 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 < 10; 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")
      |
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 712 KB Output is correct
2 Correct 2 ms 968 KB Output is correct
3 Incorrect 2 ms 960 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 328 KB Output isn't correct
2 Halted 0 ms 0 KB -