Submission #901564

#TimeUsernameProblemLanguageResultExecution timeMemory
901564ByeWorldBali Sculptures (APIO15_sculpture)C++14
37 / 100
1 ms600 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long 
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 2010;
const int MAXK = 205;
const int LOG = 31;
const int MOD = 1e9+7;
const int SQRT = 520;
const int INF = 2e12+10;
typedef pair<ll,ll> pii;
typedef pair<ll,pii> ipii;
 
int n, x, y;
int a[MAXN], pr[MAXN];
pii dp[MAXN];

signed main(){
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> x >> y;
    for(int i=1; i<=n; i++){
        cin >> a[i]; pr[i] = pr[i-1]+a[i];
    }
    int ans = (1ll<<LOG)-1;
    for(int i=LOG-1; i>=0; i--){
        dp[0] = pii(0, 0);

        int num = ans-(1ll<<i);
        for(int j=1; j<=n; j++){
            dp[j].fi = INF; dp[j].se = -1;
            for(int k=0; k<=j-1; k++){
                int seg = pr[j]-pr[k];
                if((seg|num) != num || dp[k].fi==INF) continue;  // gk valid
                
                dp[j].fi = min(dp[j].fi, dp[k].fi+1);
                dp[j].se = max(dp[j].se, dp[k].se+1);
            }
        }
        if(dp[n].fi != INF && max(x, dp[n].fi)<=min(y, dp[n].se) ){ // bisa
            ans -= (1ll<<i);
        }
    }
    cout << ans << '\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...