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, M = 1e2 + 17;
int f[N], a[N], n, u, v;
bool fz[M][M];
long long ans, s[N];
bool check (long long a, long long b, long long c)
{
    return (a | b) < (b | c);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> u >> v;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    if (u == 1)
    {
        for (int i = 40; i >= 0; --i)
        {
            long long x = 1LL << i;
            for (int j = 1; j <= n; ++j)
            {
                f[j] = n + 1;
                for (int k = 0; k < j; ++k)
                {
                    if (check (s[j] - s[k], ans, x))
                    {
                        f[j] = min (f[j], f[k] + 1);
                    }
                }
            }
            if (f[n] > v)
            {
                ans += x;
            }
        }
    }
    else
    {
        fill (fz[0], fz[0] + n + 1, 1);
        for (int i = 40; i >= 0; --i)
        {
            long long x = 1LL << i;
            for (int j = 1; j <= n; ++j)
            {
                for (int k = 0; k < j; ++k)
                {
                    if (check (s[j] - s[k], ans, x))
                    {
                        for (int t = 1; t <= j + 1; ++t)
                        {
                            fz[j][t] = fz[k][t - 1];
                        }
                    }
                }
            }
            bool z = 0;
            for (int j = u; j <= v; ++j)
            {
                if (fz[n][j])
                {
                    z = 1;
                }
            }
            if (!z)
            {
                ans += x;
            }
        }
    }
    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... |