제출 #278832

#제출 시각아이디문제언어결과실행 시간메모리
278832jainbot27Bali Sculptures (APIO15_sculpture)C++17
50 / 100
102 ms512 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int N = 2001;
int dp[N], a[N], n, aa, b, dp1[N][N];
ll mx = 0, p[N];

bool works(int bit){
    if(aa == 1){
        ll most = mx + (1LL << bit);
        for(int i=0; i<=n; i++){
            dp[i] = 1e9;
        }
        dp[0] = 0;
        for(int i=1; i <= n; i++){
            for(int j = 0; j < i; j++){
                ll sum = p[i] - p[j]; 
                if((sum|mx) < most){
                    dp[i] = min(dp[i], dp[j] + 1);
                }
            }
        }
        return dp[n]>b;
    }
    else{
        //cerr << "BIT " << bit << "\n";
        ll most = mx + (1LL << bit);
        for(int i=0; i <= n; i++){
            for(int j=0; j <= n; j++){
                dp1[i][j] = 0;
            }
        }
        dp1[0][0] = 1;
        for(int i=1; i<=n; i++){
            for(int j=1; j <= i; j++){
                for(int k=0; k <= i; k++){
                    if(dp1[k][j-1] && ((p[i] - p[k])|mx)<most){
                        dp1[i][j]|=1;
                    }
                }
            }
        }
        //for(int i = 0; i <= n; i++){
            //for(int j = 0; j <= n; j++){
                //cerr << "(" << i << "," << j << ") " << dp1[i][j] << "\n";
            //}
        //}
        for(int i = aa; i <= b; i++){
            if(dp1[n][i]){
                return 0;
            }
        }
        return 1;
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> aa >> b;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        p[i] = p[i-1] + a[i];
    }
    for(int bit = 40; bit >= 0; bit--){
        if(works(bit)){
            mx += 1LL << bit;
        }
    }
    cout << mx << "\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...