# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
726854 |
2023-04-19T12:49:50 Z |
TimDee |
Kitchen (BOI19_kitchen) |
C++17 |
|
86 ms |
724 KB |
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define s second
#define pi pair<int,int>
#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
const int inf = 1e9;
void solve() {
int n,m,k; cin>>n>>m>>k;
vii(a,n);
vii(b,m);
if (k>m) {
cout<<"Impossible";
return;
}
forn(i,n) if (a[i]<k) {
cout<<"Impossible";
return;
}
int s=0;
for(auto&x:a) s+=x;
for(auto&x:b) s-=x;
if (s>0) {
cout<<"Impossible";
return;
}
if (k==1) {
vector<int> dp(1e5,0);
dp[0]=1;
int s=0; forn(i,n) s+=a[i];
for(auto&x:b) {
for (int i=9e4; i>=0; --i) {
dp[i+x]|=dp[i];
}
}
for (int i=s; i<1e5; ++i) {
if (dp[i]) {
cout<<i-s;
return;
}
}
cout<<"Impossible";
return;
}
if (m<=15) {
int z=0;
for(auto&x:a) z+=x;
int ans=inf;
for (int mask=0; mask<(1<<m); ++mask) {
if (__builtin_popcount(mask) < k) continue;
vector<int> f;
forn(i,m) if ((mask>>i)&1) f.pb(b[i]);
int sum=0;
for(auto&x:f) sum+=x;
if (sum<z) continue;
sort(rall(f));
forn(i,n) {
forn(j,k) f[j]--;
sort(rall(f));
}
if (f.back()<0) continue;
ans=min(ans,sum-z);
}
if (ans==inf) cout<<"Impossible";
else cout<<ans;
return;
}
s=0;
for(auto&x:a) s+=x;
int ans=inf;
int mx=max({m,n,k});
for(auto&x:a) mx=max(mx,x);
for(auto&x:b) mx=max(mx,x);
if (mx>40) exit(0);
const int S=1600;
vector<int> dp(S+1,0);
dp[0]=1;
for(auto&x:b) {
if (x>=n) continue;
for (int i=S-x; i>=0; --i) dp[i+x]|=dp[i];
}
vector<vector<int>> dp2(S+1,vector<int>(m+1,0));
dp2[0][0]=1;
for(auto&x:b) {
if (x<n) continue;
for (int i=S-x; i>=0; --i) {
for (int j=m-1; j>=0; --j) {
dp2[i+x][j+1]|=dp2[i][j];
dp2[i+x][j]|=dp2[i+x][j+1];
}
}
}
for (int i=0; i<=s; ++i) {
if (!dp[i]) continue;
int x=max(k-i/n,0);
for (int j=s-i; j<=S; ++j) {
if (dp2[j][x]) ans=min(ans,i+j-s);
}
}
if (ans==inf) cout<<"Impossible";
else cout<<ans;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# |
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 |
700 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
708 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 |
212 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 |
700 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
708 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 |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
10 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
14 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
724 KB |
Output is correct |
2 |
Correct |
65 ms |
724 KB |
Output is correct |
3 |
Correct |
81 ms |
724 KB |
Output is correct |
4 |
Correct |
86 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
57 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
596 KB |
Output is correct |
2 |
Correct |
15 ms |
636 KB |
Output is correct |
3 |
Correct |
5 ms |
636 KB |
Output is correct |
4 |
Correct |
6 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
212 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 |
700 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
708 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 |
212 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
10 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
14 ms |
212 KB |
Output is correct |
14 |
Correct |
71 ms |
724 KB |
Output is correct |
15 |
Correct |
65 ms |
724 KB |
Output is correct |
16 |
Correct |
81 ms |
724 KB |
Output is correct |
17 |
Correct |
86 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
57 ms |
724 KB |
Output is correct |
20 |
Correct |
25 ms |
596 KB |
Output is correct |
21 |
Correct |
15 ms |
636 KB |
Output is correct |
22 |
Correct |
5 ms |
636 KB |
Output is correct |
23 |
Correct |
6 ms |
596 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |