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;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define pii  pair <int, int>
#define sz size()
const int N = 2e3 + 5;
ll n, A, B, dp[N], a[N], dp1[N][N];
int main() {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> A >> B;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	ll san = (1LL << 42) - 1;
	if (A == 1) {
		for (ll i = 41; i >= 0; i--) {
			san ^= (1LL << i);
			for (int j = 1; j <= n; ++j) {
				dp[j] = 2500;
			}
			for (int j = 1; j <= n; ++j) {
				ll sum = 0;
				for (int k = j; k > 0; k--) {
					sum += a[k];
					if ((san & sum) == sum) {
						dp[j] = min (dp[j], dp[k - 1] + 1);
					}
				}
			}
			if (dp[n] > B) {
				san ^= (1LL << i);
			}
		}
	}
	else {
		dp1[0][0] = 1;
		for (ll val = 41; val >= 0; val--) {
			san ^= (1LL << val);
			for (int i = 1; i <= n; ++i) {
				for (int j = 1; j <= n; ++j) {
					dp1[i][j] = 0;
				}
			}
			for (int i = 1; i <= n; ++i) {
				for (int j = 1; j <= i; ++j) {
					// dp[i][j]
					ll sum = 0;
					for (int k = i; k > 0; k--) {
						sum += a[k];
						if ((san & sum) == sum) dp1[i][j] |= dp1[k - 1][j - 1];
					}
				}
			}
			san ^= (1LL << val);
			for (int i = A; i <= B; ++i) {
				if (dp1[n][i]) {
					san ^= (1LL << val);
					break;
				}
			}
		}
	}
	cout << san;
}
| # | 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... |