This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e12;
const int N = 5001;
void solve() {
int n;
cin >> n;
int l,r;
cin >> l >> r;
vi a(n+1),p(n+1,0);
for (int i=1;i<=n;i++) cin >> a[i];
for (int i=1;i<=n;i++) p[i] = p[i-1]+a[i];
int ans = 0;
int bigbit = __lg(p[n])+1;
if (l>1) {
for (int ii=bigbit;ii>=0;ii--) {
bool dp[n+1][n+1];
memset(dp,0,sizeof dp);
dp[0][0] = 1;
for (int i=0;i<=n;i++) {
for (int j=0;j<=n;j++) {
if (!dp[i][j]) continue;
for (int k=i+1;k<=n;k++) {
int sm = p[k]-p[i];
if ((sm|ans) < ans+(1LL<<ii)) dp[k][j+1] = 1;
}
}
}
bool fl = 0;
for (int j=l;j<=r;j++) fl|=dp[n][j];
if (fl) continue;
else ans+=(1LL<<ii);
}
}
else {
for (int ii=bigbit;ii>=0;ii--) {
int dp[n+1];
for (int j=1;j<=n;j++) dp[j] = inf;
dp[0] = 0;
for (int i=0;i<=n;i++) {
if (dp[i]>r) continue;
for (int k=i+1;k<=n;k++) {
int sm = p[k]-p[i];
if ((sm|ans) < ans+(1LL<<ii)) dp[k] = min(dp[k],dp[i]+1);
}
}
bool fl = 0;
for (int j=l;j<=r;j++) fl|=(dp[n]<=r);
if (fl) continue;
else ans+=(1LL<<ii);
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |