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 ll long long
#pragma GCC optimize("Ofast")
bitset<2001> dp[2003];
ll sm[2003];
bitset<2001> mv[2003];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	for (ll i = 1; i<=n; i++){
		cin >> sm[i];
		sm[i]+=sm[i-1];
	}
	ll ans=((ll)1<<41)-1;
	dp[0][0]=1;
	for (ll u = 40; u>=0; u--){
		ll cur=ans-((ll)1<<u);
		for (ll i = 1; i<=n; i++){
			for (ll j = 0; j<i; j++){
				if ((cur|(sm[i]-sm[j]))==cur)mv[i][j]=1;
				else mv[i][j]=0;
			}
			for (ll j = i; j<=n; j++)mv[i][j]=0;
		}
		for (ll i = 1; i<=b; i++){
			for (ll j = 1; j<=n; j++){
				if ((dp[i-1]&mv[j]).any())dp[i][j]=1;
				else dp[i][j]=0;
			}
		}
		for (ll i = a; i<=b; i++){
			if (dp[i][n]){
				ans=cur;
				break;
			}
		}
	}
	cout << ans << '\n';
}
| # | 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... |