Submission #623989

# Submission time Handle Problem Language Result Execution time Memory
623989 2022-08-07T06:34:10 Z jiahng Uplifting Excursion (BOI22_vault) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 611
#define INF (ll)(1e18+10)
#define MOD 998244353
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
typedef pair <pi,pi> pipi;

int dp[maxn][maxn][maxn];
int A[maxn], sm = 0;
int M,L;
int32_t main(){
    fast;
    cin >> M >> L;
    FOR(i,0,2*M) cin >> A[i];
    vector <pii> v;
    int ans = 0;
    FOR(i,M,2*M) if (sm < L){
        if (sm + A[i] * (i-M) <= L){
            ans += A[i];
            sm += A[i] * (i-M); v.pb(pii(pi(-(i-M), A[i]), -1)); A[i] = 0;
        }else{
            int x = INF;
            if (i != M){
                x = (L - sm) / (i - M)
                if ((L - sm) % (i - M) != 0) x++;
            }
            x = min(x, A[i]);
            sm += x * (i-M); 
            A[i] -= x;
            v.pb(pii(pi(-(i-M), x), -1));
            ans += x;
        }
    }

    //cout << sm << ' ' << ans << '\n';
    //FOR(i,0,2*M) cout << A[i] << ' ';
    //cout << '\n';
    if (sm < L){
        cout << "impossible"; return 0;
    }
    assert(sm - L <= M);

    FOR(i,0,2*M) v.pb(pii(pi(i-M, A[i]), 1));

    vector <pii> pos, neg;
    aFOR(i, v) if (i.f.s > 0){
        if (i.f.f >= 0) pos.pb(i);
        else neg.pb(i);
    }

    FOR(i,0,2*M) dp[i][0][0] = -INF;
    dp[M][0][0] = 0;
        
    FOR(j,0,pos.size()) FOR(k,0,neg.size()) if (j > 0 || k > 0){
        FOR(i,0,2*M){
           dp[i][j][k] = -INF;
           if (j > 0){
                FOR(x,0,min(pos[j-1].f.s, 2*M)) if (0 <= i + x * pos[j-1].f.f && i + x * pos[j-1].f.f <= 2*M){
                    dp[i][j][k] = max(dp[i][j][k], dp[i+x*pos[j-1].f.f][j-1][k] + x * pos[j-1].s);
                }
           }
           if (k > 0){
                FOR(x,0,min(neg[k-1].f.s, 2*M)) if (0 <= i + x * neg[k-1].f.f && i + x * neg[k-1].f.f <= 2*M){
                    dp[i][j][k] = max(dp[i][j][k], dp[i+x*neg[k-1].f.f][j][k-1] + x * neg[k-1].s);
                }
           }
        }
    }
    ans += dp[sm - L + M][pos.size()][neg.size()];
    if (ans < 0) cout << "impossible";
    else cout << ans;

}

Compilation message

vault.cpp: In function 'int32_t main()':
vault.cpp:48:39: error: expected ';' before 'if'
   48 |                 x = (L - sm) / (i - M)
      |                                       ^
      |                                       ;
   49 |                 if ((L - sm) % (i - M) != 0) x++;
      |                 ~~