제출 #228915

#제출 시각아이디문제언어결과실행 시간메모리
228915mehrdad_sohrabiBali Sculptures (APIO15_sculpture)C++14
100 / 100
225 ms4480 KiB
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e3+10,M=110;
ll dp[N];
ll a[N];
bool pd[N][N];
int32_t main(){
    sync;
    ll n;
    cin >> n;
    ll b;
    ll e;
    cin >> e >> b;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    if (n<110){
        ll ans=((ll)1<<60)-1;
        for (int bit=59;bit>-1;bit--){
            ans-=((ll)1<<bit);
            memset(pd,0,sizeof pd);
            pd[0][0]=1;
            for (int i=1;i<=n;i++){
                ll cnt=0;
                for (int j=i;j;j--){
                    cnt+=a[j];
                    for (int k=1;k<M;k++){
                        if ((cnt | ans)<=ans)
                        pd[i][k]=max(pd[i][k],pd[j-1][k-1]);
                    }
                }
            }
            ll p1=0;
            for (int i=e;i<=b;i++){
                if (pd[n][i]) p1=1;
            }
            if (!p1){
                ans+=((ll)1<<bit);
            }
        }
        cout << ans << endl;
        return 0;
    }
    ll ans=((ll)1<<60)-1;
    for (int bit=59;bit>-1;bit--){
        memset(dp,63,sizeof dp);
        dp[0]=0;
        ans-=((ll)1<<bit);
        for (int i=1;i<=n;i++){
            ll cnt=0;
            for (int j=i;j;j--){
                cnt+=a[j];
                if ((cnt | ans)<=ans){
                    dp[i]=min(dp[i],dp[j-1]+1);
                }
            }
        }
        if (dp[n]>b){
            ans+=((ll)1<<bit);
        }
    }
    cout << ans << endl;
}


#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...