제출 #541047

#제출 시각아이디문제언어결과실행 시간메모리
541047MihaiPopaBali Sculptures (APIO15_sculpture)C++14
71 / 100
1088 ms1364 KiB
#include <iostream>

using namespace std;

const int NMAX = 2e3 + 2;

int N, A, B;
int v[NMAX];
long long sp[NMAX];
bool dp[NMAX][NMAX];
bool SOL[45];

static inline void Read()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> N >> A >> B;
    for(int i = 1; i <= N; ++i)
        cin >> v[i], sp[i] = sp[i - 1] + v[i];

    return;
}

static inline long long Query(int l, int r)
{
    return (sp[r] - sp[l - 1]);
}

static inline bool verify(long long X, int bit)
{
    if(X & (1LL << bit))
        return false;
    for(int i = bit + 1; i <= 40; ++i)
        if((X & (1LL << i)) && !SOL[i])
            return false;

    return true;
}

static inline bool OK(int bit)
{
    for(int i = 1; i <= N; ++i)
        for(int j = 1; j <= N; ++j)
            dp[i][j] = false;
    dp[0][0] = true;

    for(int i = 1; i <= N; ++i)
        for(int k = 1; k <= i; ++k)
            for(int j = 0; j < i; ++j)
                dp[i][k] |= (verify(Query(j + 1, i), bit) & dp[j][k - 1]);
    for(int i = A; i <= B; ++i)
        if(dp[N][i])
            return true;

    return false;
}

static inline void Solve()
{
    long long ans = 0;
    for(int i = 40; i >= 0; --i) {
        SOL[i] = !OK(i);
        ans += (SOL[i] ? (1LL << i) : 0);
    }

    cout << ans << '\n';
    return;
}

int main()
{
    Read();
    Solve();
    return 0;
}
#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...