답안 #747738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747738 2023-05-24T15:26:41 Z nguyentunglam Kitchen (BOI19_kitchen) C++17
100 / 100
36 ms 1308 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 310, M = 300 * 300;
vector<int> lst[2];
int f[M + 10], g[M + 10], h[M + 10];
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int n, m, k; cin >> n >> m >> k;
    int sum = 0, ans = 1e9;
    for(int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (x < k) return cout << "Impossible", 0;
        sum += x;
    }
    for(int i = 1; i <= m; i++) {
        int x; cin >> x;
        if (x <= n) lst[0].push_back(x);
        else lst[1].push_back(x);
    }
    f[0] = 1;
    for(int &val : lst[0]) for(int j = M; j >= val; j--) if (f[j - val]) f[j] = 1;
    h[M + 1] = 1e9;
    for(int j = M; j >= 0; j--) {
        h[j] = f[j] ? j : h[j + 1];
        g[j] = -1e9;
    }
    g[0] = 0;
    for(int &val : lst[1]) for(int j = M; j >= val; j--) g[j] = max(g[j], g[j - val] + 1);
    for(int j = 0; j <= M; j++) if (g[j] >= 0) {
        int tmp = max(n * k - g[j] * n, sum - j);
        tmp = max(tmp, 0);
        if (tmp > M) continue;
        int i = h[tmp];
        ans = min(ans, j + i - sum);
    }
    if (ans > 1e8) return cout << "Impossible", 0;
    cout << ans;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:15:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 2 ms 1032 KB Output is correct
12 Correct 2 ms 980 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1180 KB Output is correct
2 Correct 16 ms 1224 KB Output is correct
3 Correct 19 ms 1100 KB Output is correct
4 Correct 26 ms 1136 KB Output is correct
5 Correct 27 ms 1308 KB Output is correct
6 Correct 16 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 5 ms 1028 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 5 ms 976 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 2 ms 1032 KB Output is correct
12 Correct 2 ms 980 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 19 ms 1180 KB Output is correct
15 Correct 16 ms 1224 KB Output is correct
16 Correct 19 ms 1100 KB Output is correct
17 Correct 26 ms 1136 KB Output is correct
18 Correct 27 ms 1308 KB Output is correct
19 Correct 16 ms 1108 KB Output is correct
20 Correct 5 ms 980 KB Output is correct
21 Correct 5 ms 1028 KB Output is correct
22 Correct 4 ms 980 KB Output is correct
23 Correct 5 ms 976 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 27 ms 972 KB Output is correct
26 Correct 27 ms 980 KB Output is correct
27 Correct 17 ms 1104 KB Output is correct
28 Correct 22 ms 1108 KB Output is correct
29 Correct 36 ms 980 KB Output is correct
30 Correct 30 ms 1108 KB Output is correct