Submission #570448

# Submission time Handle Problem Language Result Execution time Memory
570448 2022-05-30T01:45:51 Z cpp219 Kitchen (BOI19_kitchen) C++17
100 / 100
437 ms 115912 KB
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 300 + 9;
const ll inf = 1e9 + 7;

ll n,m,k,a[N],dp[N][N*N],b[N],ans = inf,sum;

void endgame(){
    cout<<"Impossible"; exit(0);
}

ll f(ll pos,ll total){
    if (!pos && total) return -inf;
    if (!total || !pos) return 0;
    ll &res = dp[pos][total];
    if (res != -1) return res;
    res = f(pos - 1,total);
    if (total >= b[pos]) res = max(res,f(pos - 1,total - b[pos]) + min(b[pos],n));
    return res;
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n>>m>>k;
    for (ll i = 1;i <= n;i++) cin>>a[i],sum += a[i];
    for (ll i = 1;i <= m;i++) cin>>b[i];
    if (*min_element(a + 1,a + n + 1) < k) endgame();
    memset(dp,-1,sizeof(dp)); //debug(f(m,sum));
    for (ll i = sum;i < N*N;i++)
        if (f(m,i) >= n*k) ans = min(ans,i);
    if (ans == inf) endgame();
    debug(ans - sum);
}
/// be confident


Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 115772 KB Output is correct
2 Correct 45 ms 115768 KB Output is correct
3 Correct 53 ms 115732 KB Output is correct
4 Correct 54 ms 115684 KB Output is correct
5 Correct 45 ms 115780 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 45 ms 115744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 115772 KB Output is correct
2 Correct 45 ms 115768 KB Output is correct
3 Correct 53 ms 115732 KB Output is correct
4 Correct 54 ms 115684 KB Output is correct
5 Correct 45 ms 115780 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 45 ms 115744 KB Output is correct
9 Correct 60 ms 115900 KB Output is correct
10 Correct 64 ms 115684 KB Output is correct
11 Correct 60 ms 115672 KB Output is correct
12 Correct 60 ms 115740 KB Output is correct
13 Correct 54 ms 115752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 353 ms 115796 KB Output is correct
2 Correct 332 ms 115792 KB Output is correct
3 Correct 313 ms 115800 KB Output is correct
4 Correct 331 ms 115796 KB Output is correct
5 Correct 287 ms 115792 KB Output is correct
6 Correct 257 ms 115912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 115780 KB Output is correct
2 Correct 86 ms 115760 KB Output is correct
3 Correct 90 ms 115748 KB Output is correct
4 Correct 93 ms 115660 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 115772 KB Output is correct
2 Correct 45 ms 115768 KB Output is correct
3 Correct 53 ms 115732 KB Output is correct
4 Correct 54 ms 115684 KB Output is correct
5 Correct 45 ms 115780 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 45 ms 115744 KB Output is correct
9 Correct 60 ms 115900 KB Output is correct
10 Correct 64 ms 115684 KB Output is correct
11 Correct 60 ms 115672 KB Output is correct
12 Correct 60 ms 115740 KB Output is correct
13 Correct 54 ms 115752 KB Output is correct
14 Correct 353 ms 115796 KB Output is correct
15 Correct 332 ms 115792 KB Output is correct
16 Correct 313 ms 115800 KB Output is correct
17 Correct 331 ms 115796 KB Output is correct
18 Correct 287 ms 115792 KB Output is correct
19 Correct 257 ms 115912 KB Output is correct
20 Correct 86 ms 115780 KB Output is correct
21 Correct 86 ms 115760 KB Output is correct
22 Correct 90 ms 115748 KB Output is correct
23 Correct 93 ms 115660 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 262 ms 115672 KB Output is correct
26 Correct 437 ms 115816 KB Output is correct
27 Correct 188 ms 115768 KB Output is correct
28 Correct 235 ms 115792 KB Output is correct
29 Correct 310 ms 115876 KB Output is correct
30 Correct 281 ms 115748 KB Output is correct