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>
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef pair <ll, ll> pii;
const int N = 2e3 + 7;
ll n, a, b;
ll aa[N], ps[N], dp[N][N], dp2[N];
ll Sum(ll x, ll y) {
	if (!x) return ps[y];
	return ps[y] - ps[x-1];
}
int main () {
	cin >> n >> a >> b;
	
	for (int i = 1; i <= n; i++) {
		cin >> aa[i];
		ps[i] = ps[i-1] + aa[i];
	}
	
	if (a > 1) {
		ll cur = 0;
		for (int i = 41; i >= 0; i--) {
			memset(dp, 0, sizeof dp);
			dp[0][0] = 1;
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= j; k++) {
					for (int l = 1; l <= b; l++) {
						if (((Sum(k, j) >> i) & (cur >> i)) == (Sum(k, j) >> i)) dp[j][l] |= dp[k-1][l-1];
					}
				}
			}
			int ok = 0;
			for (int i = a; i <= b; i++) ok |= dp[n][i];
			if (!ok) cur |= (1LL << i);
		}
		cout << cur;
	}
	else {
		ll cur = 0;
		for (int i = 41; i >= 0; i--) {
			for (int j = 1; j <= n; j++) dp2[j] = 1e18;
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= j; k++) {
					if (((Sum(k, j) >> i) & (cur >> i)) == (Sum(k, j) >> i)) {
						dp2[j] = min(dp2[j], dp2[k-1]+1);
					}
				}
			}
			if (dp2[n] > b) cur |= (1LL << i);
		}
		cout << cur;
	}
	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... |