답안 #567342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567342 2022-05-23T10:42:50 Z RealSnake Kitchen (BOI19_kitchen) C++14
100 / 100
25 ms 1024 KB
#include "bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define mod 1000000007

ofstream fout(".out");
ifstream fin(".in");

int dp[90001], dp2[90001];

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, k;
    cin >> n >> m >> k;
    int a[n], b[m];
    int x = 0;
    bool bad = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        x += a[i];
        if(a[i] < k)
            bad = 1;
    }
    int sum = 0;
    for(int i = 0; i < m; i++) {
        cin >> b[i];
        sum += b[i];
    }
    if(bad) {
        cout << "Impossible";
        return 0;
    }
    // dp[i] = the maximum number of meals they can prepare in i hours
    dp2[0] = 1;
    for(int i = 0; i < m; i++) {
        for(int j = sum; j >= b[i]; j--) {
            dp2[j] |= dp2[j - b[i]];
            if(dp2[j - b[i]] && dp[j - b[i]] + min(n, b[i]) > dp[j])
                dp[j] = dp[j - b[i]] + min(n, b[i]);
        }
    }
    for(int i = x; i <= sum; i++) {
        if(dp[i] >= n * k) {
            cout << i - x;
            return 0;
        }
    }
    cout << "Impossible";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 852 KB Output is correct
2 Correct 12 ms 724 KB Output is correct
3 Correct 14 ms 724 KB Output is correct
4 Correct 25 ms 1024 KB Output is correct
5 Correct 23 ms 968 KB Output is correct
6 Correct 13 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 14 ms 852 KB Output is correct
15 Correct 12 ms 724 KB Output is correct
16 Correct 14 ms 724 KB Output is correct
17 Correct 25 ms 1024 KB Output is correct
18 Correct 23 ms 968 KB Output is correct
19 Correct 13 ms 716 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 10 ms 724 KB Output is correct
26 Correct 16 ms 724 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 15 ms 684 KB Output is correct
29 Correct 16 ms 848 KB Output is correct
30 Correct 25 ms 972 KB Output is correct