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 N 2005
#define K 50
using namespace std;
int arr[N];
int n,a,b;
bool dp[N][N];
int dp2[N];
bool ck(long long mask){
if(n <= 100){
for(int i=1;i<=n;i++){
for(int j = 1;j<=n;j++){
dp[i][j] = 0;
}
}
dp[0][0] = 1;
for(int i=0;i<n;i++){
for(int j = 0;j<=i;j++){
long long sum = 0;
for(int c = i+1;c<=n;c++){
sum += arr[c];
if((sum & mask) == 0){
dp[c][j+1] |= dp[i][j];
}
}
}
}
for(int i = a;i<=b;i++){
if(dp[n][i])
return dp[n][i];
}
return 0;
}
else{
for(int i = 1;i<=n;i++){
dp2[i] = 1e9;
}
for(int i=0;i<n;i++){
long long sum = 0;
for(int c = i+1;c<=n;c++){
sum += arr[c];
if((sum & mask) == 0){
dp2[c] = min(dp2[c],dp2[i] + 1);
}
}
}
return dp2[n] <= b;
}
}
void solve(){
cin >> n >> a >> b;
for(int i=1;i<=n;i++){
cin >> arr[i];
}
long long mask = 0;
for(int i = K;i>=0;i--){
if(ck(mask | (1ll<<i))){
mask |= (1ll<<i);
}
}
cout << ((1ll<<(K+1)) - 1) - mask;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#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... |