#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <bitset>
using namespace std;
int A, B, N;
vector<int64_t> Y;
bool check(int64_t banned)
{
if (A == 1) {
vector<int> dist(N + 1, B + 1);
dist[0] = 0;
for (int i = 0; i < N; ++i) if (dist[i] <= B) {
int64_t cur = 0;
for (int j = i + 1; j <= N && cur < banned; ++j) {
cur += Y[j];
if (!(cur & banned)) dist[j] = min(dist[j], dist[i] + 1);
}
}
return dist[N] <= B;
} else {
vector<vector<int>> valid(B + 1, vector<int>(N + 1, 0));
valid[0][0] = 1;
for (int i = 0; i < B; ++i) {
for (int j = 0; j < N; ++j) if (valid[i][j]) {
int64_t cur = 0;
for (int k = j + 1; k <= N && cur < banned; ++k) {
cur += Y[k];
if (!(cur & banned)) valid[i + 1][k] = true;
}
}
}
for (int i = A; i <= B; ++i) if (valid[i][N]) return true;
return false;
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> A >> B;
Y.resize(N + 1, 0);
for (int i = 1; i <= N; ++i) cin >> Y[i];
int log = __lg(accumulate(Y.begin(), Y.end(), 0ll));
int64_t banned = 0;
for (int j = log; j >= 0; --j) {
if (check(banned ^ (1ll << j))) banned ^= (1ll << j);
}
cout << (1 << (log + 1)) - 1 - banned << endl;
}
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:51:17: error: 'accumulate' was not declared in this scope
int log = __lg(accumulate(Y.begin(), Y.end(), 0ll));
^~~~~~~~~~