Submission #993492

#TimeUsernameProblemLanguageResultExecution timeMemory
993492MarwenElarbiUplifting Excursion (BOI22_vault)C++17
5 / 100
5093 ms23084 KiB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#pragma GCC optmize("O3")
#pragma GCC optmize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define int long long 
const int nax=205;
vector<pair<int,int>> objects;
void add(int x , int i)
{
    while(x)
    {
        int msb = 31 - __builtin_clz(x);
        if(x == (1<<(msb + 1)) - 1)
        {

            for(int j = 0 ; j <= msb ; j++)
            {
                objects.pb({(1<<j) * i, (1<<j)});
            }
            break;
        }
        int cur=0;
        for(int j = 0 ; j < msb ; j++)
        {
            cur+=(1<<j);
            objects.pb({(1<<j) * i , (1<<j)});
        }
        x-=cur;
    }
}
const int INF = 1e18;
signed main(){
    int m , L;
    cin>>m>>L;
    unordered_map<int ,int> dp;
    int ans = 0;
    int MX=0;
    int MN=0;
    for(int i = -m ; i <= m ; i++)
    {
        int x;
        cin>>x;
        if(i>0) MX+=x*i;
        else MN-=x*i;
        if(i == 0){
            ans=x;
        }else add(x , i);
    }
    MX=max(abs(MN),abs(MX));
    MX++;
    for(int i = -MX + 1 ; i <= MX - 1; i++)
    {
        dp[i] = -INF;
    }
    dp[0] = ans;
    sort(objects.begin(),objects.end());
    for(auto c : objects){
        if(c.fi > 0){
            for(int j = MX - 1 ; j >= -MX + 1 ; j--)
            {
                if(j - c.fi >= -MX + 1)
                    dp[j] = max(dp[j] , dp[j - c.fi] + c.se);
            }
        }else 
        {
            for(int j = -MX + 1 ; j <= MX - 1 ; j++)
            {
                if(j - c.fi <= MX - 1)
                {
                    dp[j] = max(dp[j] , dp[j - c.fi] + c.se);
                }
            }
        }
    }
    if(L>=MX||L<=-MX) cout <<"impossible"<<endl;
    else if(dp[L]<=0) cout <<"impossible"<<endl;
    else cout << dp[L]<<endl;
}

Compilation message (stderr)

vault.cpp:5: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
    5 | #pragma GCC optmize("O3")
      | 
vault.cpp:6: warning: ignoring '#pragma GCC optmize' [-Wunknown-pragmas]
    6 | #pragma GCC optmize("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...