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
ll dp[2003];
ll sm[2003];
ll oo=1e18;
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;
for (ll u = 40; u>=0; u--){
ll cur=ans-((ll)1<<u);
for (ll i = 1; i<=n; i++){
dp[i]=oo;
for (ll j = 0; j<i; j++){
if ((cur|(sm[i]-sm[j]))==cur)dp[i]=min(dp[i],1+dp[j]);
}
}
if (a<=dp[n] && dp[n]<=b){
ans=cur;
}
}
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... |