답안 #602595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602595 2022-07-23T09:13:51 Z nguyentu Kitchen (BOI19_kitchen) C++14
0 / 100
1000 ms 6120 KB
#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define ii pair<int , int>  
#define iv pair<ii , ii>
#define iii pair<int , ii>
#define fi first
#define se second
#define int long long
const int inf = 1e18 + 7;
const int MAX_N = 41;
const int MOD = 1e9 + 7;
const int MAX_V = 300 * 301;

int n , m , K;
bitset<MAX_V> f[2][301];
bitset<MAX_V> g;
bitset<MAX_V> dp; 
int a[MAX_N];
int b[MAX_N];
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m >> K;
    int W = 0 , w = 0;
    for (int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        if (a[i] < K) {
            cout << "Impossible";
            return 0;
        }
        W += a[i];
    }
    vector<int> c , d;
    for (int i = 1 ; i <= m ; i++) {
        cin >> b[i];
        if (b[i] >= K) c.push_back(b[i]);
        else d.push_back(b[i]);
        w += b[i];
    }
    if (W > w || K > m) {
        cout << "Impossible";
        return 0;
    }
    int l1 = c.size();
    int l2 = d.size();
    f[0][0] = 1;
    for (int i = 0 ; i < l1; i++) {
        int now = i & 1;
        int nxt = now ^ 1;
        for (int j = 0 ; j < l1 ; j++) { 
            f[nxt][j + 1] = ((f[now][j] << c[i]));
        }
        for (int j = 1 ; j < l1 ; j++) {
            f[now][j] = f[nxt][j];
        }
    }
    g[0] = 1;
    for (int i = 0 ; i < l2 ; i++) {
        g = g | (g << d[i]);
    }
    for (int i = K ; i <= m ; i++) {
        dp = dp | f[l1 & 1][i];
    }
    //cout << dp[231];
    // for (int i = 50 ; i <= 100 ; i++) {
    //     cout << dp[i] << " ";
    // }
    //cerr << w << " " << W;
    int ans = inf;
    for (int i = 0 ; i <= w ; i++) {
        for (int j = 0 ; j <= w ; j++) {
            if ((i + j) >= W && g[j] && dp[i]) {
                ans = min(ans , (i + j) - W);
            }
        }
    }
    if (ans == inf) cout << "Impossible";
    else cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 6120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -