Submission #1147805

#TimeUsernameProblemLanguageResultExecution timeMemory
1147805Theo830Bali Sculptures (APIO15_sculpture)C++20
37 / 100
65 ms31876 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll num = 0;
ll dp[2005][2005];
ll arr[2005];
ll n,a,b;
ll po;
ll solve(ll idx,ll j){
    if(j > b){
        return 0;
    }
    if(idx == n){
        return a <= j;
    }
    if(dp[idx][j] != -1){
        return dp[idx][j];
    }
    bool ok = 0;
    ll sum = 0;
    f(k,idx,n){
        sum += arr[k];
        ll val = sum | num;
        val -= num;
        if(val < po){
            ok |= solve(k+1,j+1);
        }
    }
    return dp[idx][j] = ok;
}
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    f(i,0,n){
        cin>>arr[i];
    }
    for(ll i = 30;i >= 0;i--){
        po = (1LL<<i);
        memset(dp,-1,sizeof dp);
        if(!solve(0,0)){
            num += po;
        }
    }
    cout<<num<<"\n";
}
#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...