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;
typedef long long ll;
const int MAXN = 2000 + 5;
const ll ziad = 1e15 + 10;
int n, a[MAXN], A, B;
ll mx = 0;
bool ok[MAXN][MAXN];
ll dp[MAXN];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> A >> B;
for(int i = 0; i < n; i ++)
cin >> a[i];
if( n <= 300){
for(int b = 40; b >= 0; b --){
memset(ok, false, sizeof ok);
ok[0][0] = true;
//if( (a[0] & mx) == 0) ok[1][1] = true;
mx ^= (1LL << b);
for(int t = 0; t <= n; t ++){
for(int i = 0; i < n; i ++){
if( !ok[i][t] ) continue;
ll sum = 0;
for(int h = i; h < n; h ++){
sum += (ll)a[h];
if( (sum & mx) == 0) ok[h + 1][t + 1] = true;
}
}
}
bool bit = false;
for(int i = A; i <= B; i ++)
bit |= ok[n][i];
if( !bit )
mx ^= (1LL << b);
}
// cout << mx << endl;
mx = (1LL << 41) - 1 - mx;
cout << mx << endl;
return 0;
}
for(int b = 40; b >= 0; b --){
fill(dp, dp + n + 1, ziad);
dp[0] = 0;
// bool bit = false;
//if( (a[0] & mx) == 0) ok[1][1] = true;
mx ^= (1LL << b);
// for(int t = 0; t <= n; t ++){
for(int i = 0; i < n; i ++){
if( dp[i] >= B ) continue;
ll sum = 0;
for(int h = i; h < n; h ++){
sum += (ll)a[h];
if( (sum & mx) == 0){
dp[h + 1] = min(dp[h + 1], dp[i] + 1);
//
}
}
}
// }
if( dp[n] > B )
mx ^= (1LL << b);
}
mx = (1LL << 41) - 1 - mx;
cout << mx << 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... |