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>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e3 + 9;
const ll inf = 1e16 + 7;
typedef pair<int,int> LL;
ll n,a[N],A,B,sum,dp[N][N],b[N],ans = (1ll << 45) - 1;
ll dp1[N],mask;
ll f(ll pos,ll grp){
if (pos > n){
if (A <= grp&&grp <= B) return 1;
return 0;
}
if (dp[pos][grp] != -1) return dp[pos][grp];
ll ans = 0;
for (ll i = pos;i <= n;i++){
ll p = b[i] - b[pos - 1];
if ((mask | p) == mask) ans = max(ans,f(i + 1,grp + 1));
}
return dp[pos][grp] = ans;
}
void Sub4(){
for (ll i = 44;i >= 0;i--){
memset(dp,-1,sizeof(dp)); mask = ans - (1ll << i);
//cout<<f(1,0)<<" x "<<mask<<"\n"; //exit(0);
if (f(1,0)) ans = mask;
}
cout<<ans;
}
ll f1(ll pos){
if (pos > n) return 0;
if (dp1[pos] != -1) return dp1[pos];
ll ans = inf;
for (ll i = pos;i <= n;i++){
ll p = b[i] - b[pos - 1];
if ((mask | p) == mask) ans = min(ans,1 + f1(i + 1));
}
return dp1[pos] = ans;
}
void Sub5(){
for (ll i = 44;i >= 0;i--){
memset(dp1,-1,sizeof(dp1)); mask = ans - (1ll << i);
if (f1(1) <= B) ans = mask;
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>A>>B;
for (ll i = 1;i <= n;i++) cin>>a[i],b[i] = b[i - 1] + a[i];
if (n <= 100) Sub4();
else Sub5();
}
Compilation message (stderr)
sculpture.cpp: In function 'int main()':
sculpture.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
59 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |