Submission #612315

# Submission time Handle Problem Language Result Execution time Memory
612315 2022-07-29T13:00:52 Z KrisjanisP Uplifting Excursion (BOI22_vault) C++14
0 / 100
155 ms 8536 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll M = 100, A = 100;

ll m, l;
ll a[2*M+1];

bool dp_right_vis[M+1][M*A+1];
ll dp_right_res[M+1][M*A+1];

// i = [1;m]
ll dp_right(ll i, ll sum)
{
    if(sum<0) return -1;
    if(sum==0) return 0;
    if(i==m+1) return -1;
    if(dp_right_vis[i][sum])
        return dp_right_res[i][sum];
    ll res = -1;
    for(ll j=0;j<=a[m+i];j++)
    {
        ll r = dp_right(i+1,sum-i*j);
        if(r==-1) continue;
        res = max(res,r+j);
    }
    dp_right_vis[i][sum] = 1;
    dp_right_res[i][sum] = res;
    return res;
}

bool dp_left_vis[M+1][M*A+1];
ll dp_left_res[M+1][M*A+1];

// i = [1;m]
ll dp_left(ll i, ll sum)
{
    if(sum<0) return -1;
    if(sum==0) return 0;
    if(i==m+1) return -1;
    if(dp_left_vis[i][sum])
        return dp_left_res[i][sum];
    ll res = -1;
    for(ll j=0;j<=a[m-i];j++)
    {
        ll r = dp_left(i+1,sum-i*j);
        if(r==-1) continue;
        res = max(res,r+j);
    }
    dp_left_vis[i][sum] = 1;
    dp_left_res[i][sum] = res;
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);

    cin>>m>>l;
    for(ll i=0;i<2*m+1;i++)
        cin>>a[i];
    ll res = a[0];
    bool found = false;
    for(ll x=0;x<=M*A;x++)
    {
        ll y = l+x;
        if(y>M*A) continue;
        ll left_res = dp_left(1,x);
        ll right_res = dp_right(1,y);
        if(left_res==-1||right_res==-1) continue;
        found = true;
        res = max(res,left_res+right_res+a[m]);
    }
    if(found)
        cout<<res<<"\n";
    else
        cout<<"impossible\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2004 KB Output is correct
5 Correct 72 ms 4616 KB Output is correct
6 Incorrect 155 ms 8536 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2004 KB Output is correct
5 Correct 72 ms 4616 KB Output is correct
6 Incorrect 155 ms 8536 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2004 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2004 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2004 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2004 KB Output is correct
5 Correct 72 ms 4616 KB Output is correct
6 Incorrect 155 ms 8536 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2004 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2004 KB Output is correct
5 Correct 72 ms 4616 KB Output is correct
6 Incorrect 155 ms 8536 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2004 KB Output is correct
2 Incorrect 1 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 788 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2004 KB Output is correct
5 Correct 72 ms 4616 KB Output is correct
6 Incorrect 155 ms 8536 KB Output isn't correct
7 Halted 0 ms 0 KB -