#include <iostream>
using namespace std;
const int NMAX = 2e3 + 2;
const int oo = 1e9;
int N, A, B;
int v[NMAX];
long long sp[NMAX];
bool dp[NMAX][NMAX];
int dp5[NMAX];
bool SOL[45];
static inline mymin(int a, int b)
{
return (a < b ? a : b);
}
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 bool OK5(int bit)
{
dp5[0] = 0;
for(int i = 1; i <= N; ++i)
dp5[i] = oo;
for(int i = 1; i <= N; ++i)
for(int j = 0; j < i; ++j)
if(verify(Query(j + 1, i), bit))
dp5[i] = (mymin(dp5[i], dp5[j] + 1));
if(dp5[N] <= B)
return true;
return false;
}
static inline void Solve5()
{
long long ans = 0;
for(int i = 40; i >= 0; --i) {
SOL[i] = !OK5(i);
ans += (SOL[i] ? (1LL << i) : 0);
}
cout << ans << '\n';
return;
}
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();
if(A == 1)
Solve5();
else Solve();
return 0;
}
Compilation message
sculpture.cpp:15:15: error: ISO C++ forbids declaration of 'mymin' with no type [-fpermissive]
15 | static inline mymin(int a, int b)
| ^~~~~