This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <fstream>
using namespace std;
const int NMAX = 2e3 + 2;
const long long INF = 1LL * 1e15;
int N, A, B;
int v[NMAX];
long long dp[NMAX][NMAX];
long long sp[NMAX];
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];
return;
}
static inline long long mymin(long long a, long long b)
{
return (a < b ? a : b);
}
long long Query(int left, int right)
{
return (sp[right] - sp[left - 1]);
}
static inline void Solve()
{
for(int i = 1; i <= N; ++i)
for(int j = 1; j <= i; ++j)
dp[i][j] = INF;
for(int i = 1; i <= N; ++i)
sp[i] = sp[i - 1] + 1LL * v[i];
for(int i = 1; i <= N; ++i)
dp[i][1] = Query(1, i);
for(int i = 1; i <= N; ++i)
for(int j = 2; j <= i; ++j)
for(int k = 0; k <= i - 1; ++k)
dp[i][j] = mymin(dp[k][j - 1] | Query(k + 1, i), dp[i][j]);
long long ans = INF;
for(int i = A; i <= B; ++i)
ans = mymin(dp[N][i], ans);
cout << ans << '\n';
}
int main()
{
Read();
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |