This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//IN THE NAME OF GOD
#include<bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#define endl '\n'
#define F first
#define S second
using namespace std;
typedef long long ll;
const ll N = 2e3+7, NN = 1e2+7;
ll a[N], dp[N], sum[N];
bool pd[NN][NN];
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,l,r; cin >> n >> l >> r;
for(ll i=1; i<=n; i++){
cin >> a[i];
sum[i] = sum[i-1] + a[i];
}
if (l != 1){
ll ans = 0;
for(ll ind = 45; ind >= 0; ind--){
pd[0][0] = 1;
for(ll i=1; i<=n; i++) for(ll j=1; j<=n; j++) pd[i][j] = 0;
for(ll i=1; i<=n; i++){
for(ll j=1; j<=i; j++){
for(ll k=i; k>=1; k--){
ll maj = sum[i] - sum[k-1];
maj -= (maj & ans);
if (maj < (1ll<<ind)) pd[i][j] |= pd[k-1][j-1];
}
}
}
bool add = 1;
for(ll j=l; j<=r; j++) if (pd[n][j]) add = 0;
if (add) ans += (1ll<<ind);
}
cout << ans << endl;
}
else{
ll ans = 0;
for(ll ind = 45; ind >= 0; ind--){
dp[0] = 0;
for(ll i=1; i<=n; i++){
dp[i] = 1e9;
for(ll j=i; j>=1; j--){
ll maj = sum[i] - sum[j-1];
maj -= (maj & ans);
if (maj < (1ll<<ind)) dp[i] = min(dp[i],dp[j-1]+1);
}
}
if (dp[n] > r) ans += (1ll<<ind);
}
cout << ans << endl;
}
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... |