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];
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;
	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);
			
		}
	}
	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... |