# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
862370 |
2023-10-18T06:34:56 Z |
maks007 |
Kitchen (BOI19_kitchen) |
C++14 |
|
30 ms |
1032 KB |
// Bismi Allah
#include "bits/stdc++.h"
using namespace std;
pair <int,int> dp[(int)1e5];
signed main () {
int n, m, k;
cin >> n >> m >> k;
int meal[n], chef[m];
for(int i = 0; i < n; i ++) cin >> meal[i];
for(int i = 0; i < m; i ++) cin >> chef[i];
if(*min_element(meal, meal + n) < k) {
cout << "Impossible";
return 0;
}
if(m < k) {
cout << "Impossible";
return 0;
}
// if(k == 1) {
// int szdp = accumulate(meal, meal + n, 0LL);
// vector <int> dp((int)1e6, 0);
// dp[0] = 1;
// for(auto j : chef) {
// for(int i = (int)1e6-1; i >= 0; i --) {
// if(!dp[i]) continue;
// dp[i+j] = 1;
// }
// }
// int mn = 1e9;
// for(int i = 0; i < dp.size(); i ++) {
// if(dp[i] == 0) continue;
// if(i < szdp) continue;
// mn = min(mn, i-szdp);
// }
// if(mn == 1e9) cout << "Impossible\n";
// else
// cout << mn << "\n";
// return 0;
// }
// if(*max_element(meal, meal + n) > 40 || *max_element(chef, chef + m) > 40){
// int ans = 1e9;
// for(int mask = 0; mask < (1 << m); mask ++) {
// if(__builtin_popcount(mask) < k) continue;
// vector <int> cook;
// for(int i = 0; i < m; i ++) {
// if(mask & (1 << i)) {
// cook.push_back(chef[i]);
// }
// }
// if(accumulate(cook.begin(), cook.end(), 0LL) < accumulate(meal, meal + n, 0LL)) continue;
// int cnt = 0, other = 0;
// for(int i = 0; i < cook.size(); i ++) {
// if(cook[i] >= n) cnt ++;
// else {
// other += cook[i];
// }
// }
// cnt += (other / n);
// if(cnt >= k)
// ans = min(ans, accumulate(cook.begin(), cook.end(), 0LL) - accumulate(meal, meal + n, 0LL));
// }
// if(ans == 1e9) cout << "Impossible";
// else
// cout << ans;
// return 0;
// }
int szdp = accumulate(meal, meal + n, 0);
// dp[0][0][0] = 1;
// for(auto coin : chef) {
// for(int i = 1699; i >= 0; i --) {
// for(int full = 0; full < 41; full ++) {
// for(int rezerv = 0; rezerv < 41; rezerv ++) {
// if(dp[i][full][rezerv]) {
// if(coin >= n) dp[i+coin][full+1][rezerv] = 1;
// else {
// dp[i+coin][full+(rezerv + coin)/n][(rezerv + coin) % n] = 1;
// }
// }
// }
// }
// }
// }
// int ans = 1e9;
// for(int i = szdp; i < 1700; i ++) {
// for(int full = k; full < 50; full ++) {
// for(int rezerv = 0; rezerv < 50; rezerv ++) {
// if(dp[i][full][rezerv])
// ans = min(ans, i-szdp);
// }
// }
// }
// if(ans == 1e9) cout << "Impossible";
// else
// cout << ans;
// queue <vector <int>> q;
// for(int i = 0; i < m; i ++) q.push({0, 0, i});
// map <pair <int,int>,int> dp;
// dp[{0,0}]=1;
// int ii = 0;
// while(!q.empty()) {
// vector <int> cur = q.front();
// q.pop();
// if(cur[2] == m) break;
// dp[{cur[0] + chef[cur[2]], cur[1] + min(chef[cur[2]], n)}] = 1;
// for(int i = 0; i < m; i ++)
// q.push({cur[0] + chef[cur[2]], cur[1] + min(chef[cur[2]], n), i});
// }
// int ans = 1e9;
// for(auto i : dp) {
// if(i.first.first >= szdp && i.first.second==n*k) ans = min(ans, i.first.first-szdp);
// }
// if(ans == 1e9) cout << "Impossible\n";
// else
// cout << ans;
dp[0]={1,0};
for(auto coin : chef) {
for(int i = (int)1e5-1; i >= 0; i --) {
if(dp[i].first == 0) continue;
dp[i+coin] = max(dp[i+coin], {1,dp[i].second+min(n,coin)});
}
}
int ans = 1e9;
for(int i = szdp; i < (int)1e5; i ++) {
if(dp[i].first == 1 && dp[i].second >= n * k) {
ans = min(ans, i-szdp);
}
}
if(ans == 1e9) cout << "Impossible";
else cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
392 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
392 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
860 KB |
Output is correct |
2 |
Correct |
13 ms |
692 KB |
Output is correct |
3 |
Correct |
28 ms |
768 KB |
Output is correct |
4 |
Correct |
30 ms |
860 KB |
Output is correct |
5 |
Correct |
27 ms |
860 KB |
Output is correct |
6 |
Correct |
12 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
392 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
15 ms |
860 KB |
Output is correct |
15 |
Correct |
13 ms |
692 KB |
Output is correct |
16 |
Correct |
28 ms |
768 KB |
Output is correct |
17 |
Correct |
30 ms |
860 KB |
Output is correct |
18 |
Correct |
27 ms |
860 KB |
Output is correct |
19 |
Correct |
12 ms |
604 KB |
Output is correct |
20 |
Correct |
4 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
14 ms |
860 KB |
Output is correct |
26 |
Correct |
16 ms |
860 KB |
Output is correct |
27 |
Correct |
10 ms |
604 KB |
Output is correct |
28 |
Correct |
20 ms |
856 KB |
Output is correct |
29 |
Correct |
23 ms |
900 KB |
Output is correct |
30 |
Correct |
30 ms |
1032 KB |
Output is correct |