#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define mp make_pair
#define pb push_back
#define INF (ll)1e18
ll MOD = (ll)(1e9+7);
ll bforce(ll n, ll l, ll r, vector<ll> &a, vector<ll> &pref){
ll res=INF;
for (ll i=0; i<(1<<n); i++){
if (!(i&(1<<(n-1)))) continue;
ll cres=0, csum=0;
for (ll j=0; j<n; j++){
csum+=a[j+1];
if (i&(1ll<<j)){
cres|=csum; csum=0;
}
}
cres|=csum;
ll cnt=__builtin_popcountll(i);
if (cnt>=l and cnt<=r) res=min(res, cres);
}
return res;
}
void solve(){
ll n, l, r; cin >> n >> l >> r;
vector<ll> a(n+1), pref(n+1);
for (ll i=1; i<=n; i++){
cin >> a[i]; pref[i]=pref[i-1]+a[i];
}
ll res=0;
for (ll i=60; i>=0; i--){
if (l==1){
vector<ll> dp(n+1, INF);
dp[0]=0;
for (ll j=1; j<=n; j++){
for (ll b=0; b<j; b++){
if ((((pref[j]-pref[b])|res)>>i)==(res>>i)){
dp[j]=min(dp[j], dp[b]+1);
}
}
}
bool pos=0;
if (dp[n]<=r) pos=1;
if (!pos){
res+=(1ull<<i);
}
}else{
vector<vector<ll>> dp(n+1, vector<ll>(r+1, 0));
dp[0][0]=1;
for (ll j=1; j<=n; j++){
for (ll k=1; k<=r; k++){
for (ll b=0; b<j; b++){
if ((((pref[j]-pref[b])|res)>>i)==(res>>i) and dp[b][k-1]){
dp[j][k]=1;
}
}
}
}
bool pos=0;
for (ll j=l; j<=r; j++){
if (dp[n][j]){
pos=1;
}
}
if (!pos){
res+=(1ull<<i);
}
}
}
cout << res << ln;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifdef LOCAL
auto start = chrono::high_resolution_clock::now();
#endif
ll testc=1;
// cin >> testc;
for (ll __c=1; __c<=testc; __c++) solve();
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
}
# | 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... |