제출 #671129

#제출 시각아이디문제언어결과실행 시간메모리
671129fatemetmhrBali Sculptures (APIO15_sculpture)C++17
75 / 100
124 ms344 KiB
// fikhshal chye daram code miznm :}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define all(x) x.begin(), x.end()
#define pb     push_back
#define fi     first
#define se     second

const int maxn5 = 2e3 + 10;
const int maxn3 = 105;
const int lg    = 41;

int n, ln, rn, dp[maxn5], a[maxn5];
bool av[maxn3][maxn3];

inline bool check(ll lim){
    //cout << "lim = " << lim << endl;
    if(ln == 1){
        for(int i = 0; i < n; i++){
            ll cur = 0;
            dp[i] = rn + 1;
            for(int j = i; j; j--){
                cur += a[j];
                //cout << "aha " << i << ' ' << j << ' ' << cur << ' ' << (cur | lim) << endl;
                if((cur | lim) == lim)
                    dp[i] = min(dp[i], dp[j - 1] + 1);
            }
            cur += a[0];
            if((cur | lim) == lim)
                dp[i] = 1;
            //cout << "ok " << i << ' ' << dp[i] << endl;
        }
        return dp[n - 1] <= rn;
    }
    memset(av, false, sizeof av);
    for(int i = 0; i < n; i++){
        ll cur = 0;
        for(int j = i; j; j--){
            cur += a[i];
            if((cur | lim) == lim){
                for(int k = 0; k < rn; k++)
                    av[i][k + 1] |= av[j - 1][k];
            }
        }
        cur += a[0];
        if((cur | lim) == lim){
            av[i][1] = true;
        }
    }
    bool re = false;
    for(int i = ln; i <= rn; i++)
        re |= av[n - 1][i];
    return re;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); 

    cin >> n >> ln >> rn;

    for(int i = 0; i < n; i++)
        cin >> a[i];

    if(ln != 1){
        ll ans = (1LL << lg) - 1;
        for(int mask = 0; mask < (1 << n); mask++) if((mask & 1) && __builtin_popcount(mask) >= ln && __builtin_popcount(mask) <= rn){
            ll sum = 0, orr = 0;
            for(int i = n - 1; i >= 0; i--){
                sum += a[i];
                if((mask >> i)&1){
                    orr |= sum;
                    sum = 0;
                }
            }
            ans = min(ans, orr);
        }
        cout << ans << endl;
        return 0;

    }

    ll cur = (1LL << lg) - 1;
    for(int i = lg - 1; i >= 0; i--){
        if(check(cur ^ (1LL << i)))
            cur ^= (1LL << i);
    }

    cout << cur << endl;

}

/*
6 1 3
8 1 2 1 5 4
*/
#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...