Submission #720151

# Submission time Handle Problem Language Result Execution time Memory
720151 2023-04-07T13:56:40 Z Rafi22 Uplifting Excursion (BOI22_vault) C++14
5 / 100
1363 ms 936 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int M=207;

ll a[2*M];
ll b[2*M];

ll DP[M*M*4];

void gg()
{
    cout<<"impossible";
    exit(0);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int m;
    ll l,sum=0,ans=0,act=0,X=0,Y=0;
    cin>>m>>l;
    for(ll i=-m;i<=m;i++)
    {
        cin>>a[i+m];
        sum+=a[i+m]*i;
        if(i<0) X+=a[i+m]*i;
        else Y+=a[i+m]*i;
    }
    if(l<0&&l<X) gg();
    if(l>0&&Y<l) gg();
    ans+=a[m];
    a[m]=0;
    if(sum>=l)
    {
        for(ll i=-m;i<=m;i++)
        {
            ll x;
            if(i<=0) x=a[i+m];
            else x=min(a[i+m],(l-act)/i);
            b[-i+m]+=x;
            a[i+m]-=x;
            ans+=x;
            act+=i*x;
        }
    }
    else
    {
        for(ll i=m;i>=-m;i--)
        {
            ll x;
            if(i>=0) x=a[i+m];
            else x=min(a[i+m],(l-act)/i);
            b[-i+m]+=x;
            a[i+m]-=x;
            ans+=x;
            act+=x*i;
        }
    }
    for(int i=-4*m*m;i<=4*m*m;i++) DP[i+4*m*m]=-infl;
    DP[4*m*m]=0;
    for(int i=-m;i<=m;i++)
    {
        for(int j=-4*m*m;j<=4*m*m;j++)
        {
            for(int l=1;l<=min((ll)2*m+1,a[i+m]+b[i+m]);l++)
            {
                int k=j+l*i;
                if(k<-4*m*m||k>4*m*m) continue;
                ll x=min(a[i+m],(ll)l)-max(0LL,l-a[i+m]);
                DP[k+4*m*m]=max(DP[k+4*m*m],DP[j+4*m*m]+x);
            }
        }
    }
    l-=act;
    if(l<-4*m*m||l>4*m*m) gg();
    else
    {
        if(ans+DP[l+4*m*m]<0) gg();
        cout<<ans+(ll)DP[l+4*m*m];
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 92 ms 468 KB Output is correct
7 Correct 38 ms 468 KB Output is correct
8 Correct 87 ms 588 KB Output is correct
9 Correct 156 ms 480 KB Output is correct
10 Correct 5 ms 484 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 92 ms 468 KB Output is correct
7 Correct 38 ms 468 KB Output is correct
8 Correct 87 ms 588 KB Output is correct
9 Correct 156 ms 480 KB Output is correct
10 Correct 5 ms 484 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 92 ms 468 KB Output is correct
18 Correct 38 ms 468 KB Output is correct
19 Correct 89 ms 504 KB Output is correct
20 Correct 155 ms 468 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 5 ms 484 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1363 ms 936 KB Output is correct
25 Incorrect 477 ms 936 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 92 ms 468 KB Output is correct
7 Correct 38 ms 468 KB Output is correct
8 Correct 87 ms 588 KB Output is correct
9 Correct 156 ms 480 KB Output is correct
10 Correct 5 ms 484 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 14 ms 384 KB Output is correct
14 Incorrect 4 ms 340 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 92 ms 468 KB Output is correct
7 Correct 38 ms 468 KB Output is correct
8 Correct 87 ms 588 KB Output is correct
9 Correct 156 ms 480 KB Output is correct
10 Correct 5 ms 484 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 92 ms 468 KB Output is correct
18 Correct 38 ms 468 KB Output is correct
19 Correct 89 ms 504 KB Output is correct
20 Correct 155 ms 468 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 5 ms 484 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1363 ms 936 KB Output is correct
25 Incorrect 477 ms 936 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 92 ms 468 KB Output is correct
7 Correct 38 ms 468 KB Output is correct
8 Correct 87 ms 588 KB Output is correct
9 Correct 156 ms 480 KB Output is correct
10 Correct 5 ms 484 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 92 ms 468 KB Output is correct
18 Correct 38 ms 468 KB Output is correct
19 Correct 89 ms 504 KB Output is correct
20 Correct 155 ms 468 KB Output is correct
21 Correct 5 ms 468 KB Output is correct
22 Correct 5 ms 484 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1363 ms 936 KB Output is correct
25 Incorrect 477 ms 936 KB Output isn't correct
26 Halted 0 ms 0 KB -