Submission #1083540

# Submission time Handle Problem Language Result Execution time Memory
1083540 2024-09-03T13:04:46 Z browntoad Kitchen (BOI19_kitchen) C++14
100 / 100
14 ms 1680 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define f first
#define s second
#define pb push_back
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 
const ll maxn = 305;
const ll mod = 1e9+7;
const ll inf = 1ll<<60;
 
ll mpw(ll a, ll p, ll m = mod){
    ll ret = 1;
    while(p > 0){
        if (p & 1){
            ret *= a;
            ret %= m;
        }
        p >>= 1;
        a *= a;
        a %= m;
    }
    return ret;
}
ll inv(ll a){
    return mpw(a, mod-2);
}
 
int n, m, k;
 
int dp[2][maxn*maxn];
signed main(){
    IOS();
    cin>>n>>m>>k;
 
    int tot = 0;
    REP(i, n){
        int tt; cin>>tt;
        tot += tt;
        if (tt < k){
            cout<<"Impossible"<<endl;
            return 0;
        }
    }
 
    REP1(j, maxn*maxn-1){
        dp[0][j] = -mod; // -inf hehe
    }
 
    int bsm = 0;
    REP1(i, m){
        int b; cin>>b;
        bsm += b;
        REP(j, bsm+1){
            dp[i&1][j] = dp[(i^1)&1][j];
            if (j > bsm-b) dp[i&1][j] = -mod;
            if (j >= b) dp[i&1][j] = max(dp[i&1][j], dp[(i^1)&1][j-b] + min(b, n));
        }
    }
 
    int ret = -1;
    FOR(i, tot, bsm+1){
        if (dp[m&1][i] >= n*k){
            ret = i;
            break;
        }
    }
 
    if (ret == -1) cout<<"Impossible"<<endl;
    else {
        cout<<ret-tot<<endl;
    }
}
/*
5 4 1
3 4 5 2 1
3 3 7 6
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 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 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 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 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 0 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1628 KB Output is correct
2 Correct 7 ms 1624 KB Output is correct
3 Correct 9 ms 1372 KB Output is correct
4 Correct 13 ms 1680 KB Output is correct
5 Correct 13 ms 1628 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 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 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 0 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 0 ms 1116 KB Output is correct
14 Correct 12 ms 1628 KB Output is correct
15 Correct 7 ms 1624 KB Output is correct
16 Correct 9 ms 1372 KB Output is correct
17 Correct 13 ms 1680 KB Output is correct
18 Correct 13 ms 1628 KB Output is correct
19 Correct 7 ms 1372 KB Output is correct
20 Correct 1 ms 1368 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 0 ms 1116 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 8 ms 1624 KB Output is correct
26 Correct 9 ms 1628 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 8 ms 1372 KB Output is correct
29 Correct 11 ms 1556 KB Output is correct
30 Correct 14 ms 1628 KB Output is correct