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 <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 17;
int n, a, b, y[N];
long long st[4 * N], f[N][N], ans;
void build (int id, int l, int r)
{
if (l == r)
{
st[id] = y[l];
return;
}
int mid = (l + r) / 2;
build (id * 2, l, mid);
build (id * 2 + 1, mid + 1, r);
st[id] = st[id * 2] + st[id * 2 + 1];
}
long long get (int id, int l, int r, int u, int v)
{
if (u <= l && r <= v)
{
return st[id];
}
int mid = (l + r) / 2;
if (v <= mid)
{
return get (id * 2, l, mid, u, v);
}
if (u > mid)
{
return get (id * 2 + 1, mid + 1, r, u, v);
}
return get (id * 2, l, mid, u, v) + get (id * 2 + 1, mid + 1, r, u, v);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i)
{
cin >> y[i];
}
build (1, 1, n);
long long s = 0;
for (int i = 1; i <= n; ++i)
{
fill (f[i] + 1, f[i] + b + 1, 1e18);
s += y[i];
f[i][1] = s;
}
for (int i = 1; i <= n; ++i)
{
for (int j = 2; j <= min (i, b); ++j)
{
for (int t = j - 1; t < i; ++t)
{
f[i][j] = min (f[i][j], f[t][j - 1] | get (1, 1, n, t + 1, i));
}
}
}
ans = 1e18;
for (int i = a; i <= b; ++i)
{
ans = min (ans, f[n][i]);
}
cout << ans;
}
# | 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... |