이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
    {
        for (int i = 40; i >= 0; --i)
        {
            long long x = 1LL << i;
            for (int j = 1; j <= n; ++j)
            {
                fz[j][0] = 1;
                for (int k = 1; k <= n; ++k)
                {
                    fz[j][k] = 0;
                }
            }
            fz[0][0] = 1;
            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... |