답안 #122998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122998 2019-06-30T01:08:11 Z model_code Kitchen (BOI19_kitchen) C++17
100 / 100
68 ms 760 KB
//Author: Oliver-Matis Lill
//O(N M B_max) DP solution. Finds maximum "diversity box filled" for a given total hour count
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

int sum(vector<int> &a) {
    return accumulate(a.begin(), a.end(), 0);
}

int min(vector<int> &a) {
    return *min_element(a.begin(), a.end());
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, k;
    cin >> n >> m >> k;
    
    vector<int> A(n), B(m);
    for(int i=0; i<n; i++) {
        cin >> A[i];
    }
    for(int i=0; i<m; i++) {
        cin >> B[i];
    }
    
    if(min(A) < k) {
        cout << "Impossible\n";
        return 0;
    }
    
    vector<int> dp((m+1)*301, -1);
    dp[0] = 0;
    
    for(int i=0; i<m; i++) {
        for(int j=dp.size()-B[i]-1; j >= 0; j--) {
            if(dp[j] != -1) {
                dp[j+B[i]] = max(dp[j+B[i]], dp[j] + min(B[i], n));
            }
        }
    }
    
    int result = INF;
    int a_sum = sum(A);
    for(int j=a_sum; j<(int)dp.size(); j++) {
        if(dp[j] >= n*k) {
            result = min(result, j - a_sum);
        }
    }
    
    if(result == INF) {
        cout << "Impossible\n";
    } else {
        cout << result << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 632 KB Output is correct
2 Correct 24 ms 632 KB Output is correct
3 Correct 53 ms 760 KB Output is correct
4 Correct 68 ms 760 KB Output is correct
5 Correct 58 ms 632 KB Output is correct
6 Correct 21 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 404 KB Output is correct
5 Correct 2 ms 276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 31 ms 632 KB Output is correct
15 Correct 24 ms 632 KB Output is correct
16 Correct 53 ms 760 KB Output is correct
17 Correct 68 ms 760 KB Output is correct
18 Correct 58 ms 632 KB Output is correct
19 Correct 21 ms 632 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 404 KB Output is correct
24 Correct 2 ms 276 KB Output is correct
25 Correct 17 ms 632 KB Output is correct
26 Correct 43 ms 632 KB Output is correct
27 Correct 16 ms 504 KB Output is correct
28 Correct 39 ms 760 KB Output is correct
29 Correct 48 ms 632 KB Output is correct
30 Correct 67 ms 632 KB Output is correct