# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
586932 | 2022-07-01T05:28:41 Z | 박상훈(#8395) | Kitchen (BOI19_kitchen) | C++17 | 260 ms | 4676 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; int a[303], b[303], mn[90090], n, m, k; bool dp[2][303][90090], dp2[2][90090]; void calc1(vector<int> &a){ dp[0][0][0] = 1; for (int i=0;i<(int)a.size();i++){ for (int j=0;j<=i;j++){ for (int k=n*j;k<=300*j;k++) if (dp[i&1][j][k]){ dp[(i+1)&1][j][k] = 1; dp[(i+1)&1][j+1][k+a[i]] = 1; } } } } void calc2(vector<int> &a){ dp2[0][0] = 1; for (int i=0;i<(int)a.size();i++){ for (int j=0;j<90090;j++) if (dp2[i&1][j]){ dp2[(i+1)&1][j] = 1; dp2[(i+1)&1][j+a[i]] = 1; } } mn[90001] = 1e9; for (int i=90000;i>=0;i--){ mn[i] = mn[i+1]; if (dp2[(int)a.size()&1][i]) mn[i] = i; } } void NO(){ printf("Impossible\n"); exit(0); } int main(){ int S = 0; scanf("%d %d %d", &n, &m, &k); for (int i=1;i<=n;i++){ scanf("%d", a+i); if (a[i]<k) NO(); S += a[i]; } vector<int> A, B; for (int i=1;i<=m;i++){ scanf("%d", b+i); if (b[i]>=n) A.push_back(b[i]); else B.push_back(b[i]); } calc1(A); calc2(B); int ans = 1e9; for (int i=0;i<=(int)A.size();i++){ for (int j=n*i;j<=300*i;j++) if (dp[(int)A.size()&1][i][j]){ int x = max(0, max(n*(k-i), S-j)); ans = min(ans, mn[x]+j - S); } } if (ans>90000) NO(); printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Output is correct |
2 | Correct | 1 ms | 696 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Output is correct |
2 | Correct | 1 ms | 696 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
9 | Correct | 1 ms | 696 KB | Output is correct |
10 | Correct | 1 ms | 724 KB | Output is correct |
11 | Correct | 1 ms | 724 KB | Output is correct |
12 | Correct | 2 ms | 596 KB | Output is correct |
13 | Correct | 2 ms | 568 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 660 KB | Output is correct |
2 | Correct | 20 ms | 716 KB | Output is correct |
3 | Correct | 34 ms | 700 KB | Output is correct |
4 | Correct | 31 ms | 1740 KB | Output is correct |
5 | Correct | 34 ms | 1016 KB | Output is correct |
6 | Correct | 19 ms | 780 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 852 KB | Output is correct |
2 | Correct | 2 ms | 724 KB | Output is correct |
3 | Correct | 3 ms | 696 KB | Output is correct |
4 | Correct | 3 ms | 724 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Output is correct |
2 | Correct | 1 ms | 696 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
9 | Correct | 1 ms | 696 KB | Output is correct |
10 | Correct | 1 ms | 724 KB | Output is correct |
11 | Correct | 1 ms | 724 KB | Output is correct |
12 | Correct | 2 ms | 596 KB | Output is correct |
13 | Correct | 2 ms | 568 KB | Output is correct |
14 | Correct | 24 ms | 660 KB | Output is correct |
15 | Correct | 20 ms | 716 KB | Output is correct |
16 | Correct | 34 ms | 700 KB | Output is correct |
17 | Correct | 31 ms | 1740 KB | Output is correct |
18 | Correct | 34 ms | 1016 KB | Output is correct |
19 | Correct | 19 ms | 780 KB | Output is correct |
20 | Correct | 3 ms | 852 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 3 ms | 696 KB | Output is correct |
23 | Correct | 3 ms | 724 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 104 ms | 2288 KB | Output is correct |
26 | Correct | 186 ms | 4676 KB | Output is correct |
27 | Correct | 37 ms | 1764 KB | Output is correct |
28 | Correct | 65 ms | 2236 KB | Output is correct |
29 | Correct | 260 ms | 3556 KB | Output is correct |
30 | Correct | 32 ms | 2132 KB | Output is correct |