답안 #1105871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105871 2024-10-28T07:39:12 Z vjudge1 Kitchen (BOI19_kitchen) C++17
51 / 100
73 ms 3408 KB
#include <bits/stdc++.h>
 
int main() {
    std::ios_base::sync_with_stdio(false); 
    std::cin.tie(nullptr);
 
    int n, m, k;
    std::cin >> n >> m >> k;
    std::vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    int64_t suma = 0;
    for (int i = 0; i < n; i++) {
        suma += a[i];
    }
    int64_t sumb = 0;
    for (int i = 0; i < m; i++) {
        sumb += b[i];
    }
    if (k == 1) {
        std::vector<std::vector<bool>> dp(m + 1, std::vector<bool>(sumb + 1, false));
        dp[0][0] = 1;
        for (int i = 1; i <= m; i++) {
            for (int j = 0; j <= sumb; j++) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j]);
                if (j >= b[i - 1]) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i - 1]]);
                }
            }
        }
        for (int j = suma; j <= sumb; j++) {
            if (dp[m][j] == 1) {
                std::cout << j - suma << "\n";
                return 0;
            }
        }
        std::cout << "Impossible\n";
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (a[i] < k) {
            std::cout << "Impossible\n";
            return 0;
        }
    }
    int64_t ans = LLONG_MAX;
    for (int mask = 0; mask < (1 << m); mask++) {
        std::vector<int> chefs;
        int64_t sum = 0;
        for (int i = 0; i < m; ++i) {
            if (mask & (1 << i)) {
                chefs.push_back(b[i]);
                sum += b[i];
            }
        }
        if (sum < suma) {
            continue;
        }
        int64_t cur = 0;
        for (auto i : chefs) {
            cur += std::min(i, n);
        }
        if (cur >= n * k) {
            ans = std::min(ans, sum - suma);
        }
    }
    if (ans != LLONG_MAX) {
        std::cout << ans << "\n";
        return 0;
    }
    std::cout << "Impossible\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 5 ms 456 KB Output is correct
12 Correct 5 ms 336 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 2384 KB Output is correct
2 Correct 39 ms 1872 KB Output is correct
3 Correct 41 ms 2128 KB Output is correct
4 Correct 70 ms 3408 KB Output is correct
5 Correct 73 ms 3408 KB Output is correct
6 Correct 32 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 5 ms 456 KB Output is correct
12 Correct 5 ms 336 KB Output is correct
13 Correct 5 ms 336 KB Output is correct
14 Correct 55 ms 2384 KB Output is correct
15 Correct 39 ms 1872 KB Output is correct
16 Correct 41 ms 2128 KB Output is correct
17 Correct 70 ms 3408 KB Output is correct
18 Correct 73 ms 3408 KB Output is correct
19 Correct 32 ms 1616 KB Output is correct
20 Incorrect 1 ms 504 KB Output isn't correct
21 Halted 0 ms 0 KB -