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 <set>
#include <algorithm>
#include <vector>
#include <assert.h>
#define ll long long
using namespace std;
const ll INF = 1e16;
const int LG = 40;
int n, l, r;
ll pref[2001];
bool dp[101][101];
int dp2[2001];
int main()
{
cin >> n >> l >> r;
for (int i = 1; i <= n; i++)
{
cin >> pref[i];
pref[i] += pref[i - 1];
}
if (l > 1)
{
ll curPref = 0;
for (int i = LG; i >= 0; i--)
{
ll checkAgainst = curPref | ((1LL << i) - 1);
for (int j = 0; j <= n; j++)
{
for (int k = 0; k <= n; k++) dp[j][k] = 0;
}
dp[0][0] = 1;
for (int j = 0; j < n; j++)
{
for (int k = 0; k < n; k++)
{
if (dp[j][k])
{
for (int l = k + 1; l <= n; l++)
{
if (((pref[l] - pref[k]) | checkAgainst) == checkAgainst) dp[j + 1][l] |= dp[j][k];
}
}
}
}
for (int j = l; j <= r; j++)
{
if (dp[j][n]) {break;}
else if (j == r) {curPref |= (1LL << i);}
}
}
cout << curPref << "\n";
}
else
{
ll curPref = 0;
for (int i = LG; i >= 0; i--)
{
ll checkAgainst = curPref | ((1LL << i) - 1);
for (int j = 0; j <= n; j++) dp2[j] = 1000000000;
dp2[0] = 0;
for (int k = 0; k < n; k++)
{
if (dp2[k] != 1000000000)
{
for (int l = k + 1; l <= n; l++)
{
if (((pref[l] - pref[k]) | checkAgainst) == checkAgainst) dp2[l] = min(dp2[l], dp2[k] + 1);
}
}
}
if (dp2[n] > r) {curPref |= (1LL << i);}
}
cout << curPref << "\n";
}
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... |