답안 #938741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938741 2024-03-05T13:35:48 Z Alebn Kitchen (BOI19_kitchen) C++14
29 / 100
71 ms 3480 KB
#include <bits/stdc++.h>
#define int long long
#define M 302
 
using namespace std;
 
int n, m, k, A = 0, B = 0, res = LLONG_MAX;
bool flag = false;
vector<int> a, b;
vector<vector<bool>> dp;
 
signed main() {
    cin >> n >> m >> k;
    a = vector<int>(n), b = vector<int>(m);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        A += a[i];
        if(a[i] < k) flag = true;
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
        B += b[i];
    }
    if(k > 1 || m <= 15) {
        // try every subset
    vector<int> diff;
    bitset<M> bin;
    int temp, sum;
    bool check;
    for(int i = 0; i < (1 << m); i++) {
        bin = bitset<M>(i), diff = vector<int>(n, k), sum = 0, check = true;
        for(int j = 0; j < M; j++) {
            if(bin[j]) {
                sum += b[j];
                temp = b[j];
                for(int k = 0; k < n && temp; k++) {
                    if(diff[k]) {
                        diff[k]--;
                        temp--;
                    }
                }
            }
        }
        for(int j = 0; j < n; j++) {
            if(diff[j]) {
                check = false;
                break;
            }
        }
        if(check && sum >= A) res = min(res, sum - A);
    }
    if(flag || res == LLONG_MAX) cout << "Impossible\n";
    else cout << res << "\n";
    } else {
    dp = vector<vector<bool>>(m + 1, vector<bool>(B + 1, false));
    dp[0][0] = true;
    for(int i = 1; i <= m; i++) {
        for(int j = 0; j <= B; j++) {
            if(j >= b[i - 1]) dp[i][j] = dp[i - 1][j] | dp[i - 1][j - b[i - 1]];
            //cout << dp[i][j] << " ";
        }
        //cout << "\n";
    }
    //
    int res = LLONG_MAX;
    for(int i = 0; i <= m; i++) {
        for(int j = A; j <= B; j++) {
            if(dp[i][j]) res = min(res, j - A);
        }
    }
    if(res == LLONG_MAX) cout << "Impossible\n";
    else cout << res << "\n";}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 19 ms 348 KB Output is correct
11 Correct 15 ms 348 KB Output is correct
12 Correct 17 ms 428 KB Output is correct
13 Incorrect 67 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2392 KB Output is correct
2 Correct 38 ms 1880 KB Output is correct
3 Correct 41 ms 2136 KB Output is correct
4 Correct 71 ms 3476 KB Output is correct
5 Correct 71 ms 3480 KB Output is correct
6 Correct 31 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 19 ms 348 KB Output is correct
11 Correct 15 ms 348 KB Output is correct
12 Correct 17 ms 428 KB Output is correct
13 Incorrect 67 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -