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;
inline namespace
{
} // namespace
void solve()
{
int n, a, b;
cin >> n >> a >> b;
vector<long> y(n);
for (long &u : y)
cin >> u;
vector<long> pref(n + 1);
pref[0] = 0;
for (int i = 0; i < n; i++)
pref[i + 1] = pref[i] + y[i];
long res = 0;
if (n <= 100)
{
for (int s = __lg(pref[n]); s >= 0; s--)
{
long comp = ~((1l << s) - 1);
vector dp(n + 1, vector<bool>(b + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
{
for (int k = 1; k <= b; k++)
{
for (int j = 0; j < i; j++)
{
if ((res | ((pref[i] - pref[j]) & comp)) == res)
{
if (dp[j][k - 1])
{
dp[i][k] = 1;
break;
}
}
}
}
}
bool ok = 0;
for (int i = a; i <= b; i++)
{
if (dp[n][i])
{
ok = 1;
break;
}
}
if (!ok)
res |= 1l << s;
}
}
else
{
for (int s = __lg(pref[n]); s >= 0; s--)
{
long comp = ~((1l << s) - 1);
vector<int> dp(n + 1, n + 1);
dp[0] = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
if ((res | ((pref[i] - pref[j]) & comp)) == res)
dp[i] = min(dp[i], dp[j] + 1);
}
}
if (dp[n] > b)
res |= 1l << s;
}
}
cout << res << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
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... |