# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
757798 |
2023-06-13T18:35:15 Z |
taher |
Kitchen (BOI19_kitchen) |
C++17 |
|
1000 ms |
11260 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 300 * 300 + 5;
bool visited[305][N];
int ndp[N];
const int maxN = 305;
int a[maxN], b[maxN];
const int inf = 1000000000;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
bool found = false;
int n, m, k;
cin >> n >> m >> k;
int tot = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
tot += a[i];
if (a[i] < k) {
found = true;
}
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
int ans = inf;
vector<int> long_ids;
vector<int> short_ids;
for (int i = 0; i < m; i++) {
if (b[i] >= n) {
long_ids.push_back(i);
} else {
short_ids.push_back(i);
}
}
ndp[0] = 1;
for (int i = 0; i < (int) long_ids.size(); i++) {
for (int it = N - 1 - b[long_ids[i]]; it >= 0; it--) {
if (ndp[it] > 0) {
ndp[it + b[long_ids[i]]] = max(ndp[it + b[long_ids[i]]], ndp[it] + 1);
}
}
}
for (int i = 0; i < N; i++) {
if (ndp[i] > 0) --ndp[i];
}
function<void(int, int)> Rec = [&](int i, int sum) {
if (visited[i][sum]) {
return ;
}
if (i == (int) short_ids.size()) {
if (sum >= max(n * k, tot)) {
ans = min(ans, sum - tot);
return ;
}
int ptr = tot - sum;
while (ptr < N && sum + n * ndp[ptr] < n * k) ptr++;
if (ptr < N && ndp[ptr] > 0) {
ans = min(ans, sum + ptr - tot);
}
return ;
}
Rec(i + 1, sum + b[short_ids[i]]);
Rec(i + 1, sum);
visited[i][sum] = true;
return ;
};
Rec(0, 0);
if (ans < inf && !found) {
cout << ans << '\n';
} else {
cout << "Impossible\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 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 |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 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 |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
26 ms |
732 KB |
Output is correct |
13 |
Correct |
117 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
10088 KB |
Output is correct |
2 |
Correct |
57 ms |
7748 KB |
Output is correct |
3 |
Correct |
177 ms |
8840 KB |
Output is correct |
4 |
Correct |
113 ms |
6076 KB |
Output is correct |
5 |
Correct |
192 ms |
11260 KB |
Output is correct |
6 |
Correct |
56 ms |
6532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
19 ms |
724 KB |
Output is correct |
3 |
Correct |
58 ms |
724 KB |
Output is correct |
4 |
Correct |
90 ms |
764 KB |
Output is correct |
5 |
Correct |
71 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 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 |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
26 ms |
732 KB |
Output is correct |
13 |
Correct |
117 ms |
760 KB |
Output is correct |
14 |
Correct |
123 ms |
10088 KB |
Output is correct |
15 |
Correct |
57 ms |
7748 KB |
Output is correct |
16 |
Correct |
177 ms |
8840 KB |
Output is correct |
17 |
Correct |
113 ms |
6076 KB |
Output is correct |
18 |
Correct |
192 ms |
11260 KB |
Output is correct |
19 |
Correct |
56 ms |
6532 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
19 ms |
724 KB |
Output is correct |
22 |
Correct |
58 ms |
724 KB |
Output is correct |
23 |
Correct |
90 ms |
764 KB |
Output is correct |
24 |
Correct |
71 ms |
756 KB |
Output is correct |
25 |
Correct |
11 ms |
596 KB |
Output is correct |
26 |
Correct |
14 ms |
692 KB |
Output is correct |
27 |
Correct |
406 ms |
1132 KB |
Output is correct |
28 |
Correct |
811 ms |
2212 KB |
Output is correct |
29 |
Correct |
55 ms |
588 KB |
Output is correct |
30 |
Execution timed out |
1087 ms |
4064 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |