#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
#define int long long
ll dp2[2001], arr[2000], n, a, b;
bool dp1[2001][2001];
ll powfunc(int a) {
ll val = 1;
for (int i=0;i<a;i++) {
val *= 2;
}
return val;
}
bool solve(ll val) {
if (a != 1) {
dp1[0][0] = true;
for (int i=1;i<n+1;i++) {
dp1[0][i] = false;
}
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
int sum = 0;
dp1[i + 1][j + 1] = false;
for (int k=j;k>-1;k--) {
sum += arr[k];
if ((sum & val) == sum) dp1[i + 1][j + 1] = (dp1[i][k] || dp1[i + 1][j + 1]);
}
}
}
//cout << val << '\n';
//for (int i=0;i<n;i++) {
// for (int j=0;j<n;j++) {
// cout << dp1[i][j] << ' ';
// } cout << '\n';
//} cout << '\n';
for (int i=a;i<=b;i++) {
if (dp1[i][n]) return true;
} return false;
} else {
for (int i=0;i<n+1;i++) {
dp2[i] = 1000000;
}
dp2[0] = 0;
for (int i=0;i<n;i++) {
int sum = 0;
for (int j=i;j>-1;j--) {
sum += arr[j];
if ((sum & val) == sum) dp2[i + 1] = min(dp2[i + 1], dp2[j] + 1);
}
}
//cout << val << '\n';
//for (int i=0;i<n+1;i++) {
// cout << dp2[i] << ' ';
//} cout << '\n';
if (dp2[n] > b) return false;
else return true;
}
}
int32_t main() {
cin >> n >> a >> b;
for (int i=0;i<n;i++) {
cin >> arr[i];
}
ll ans = powfunc(42) - 1;
for (int i=41;i>-1;i--) {
ans -= powfunc(i);
if (solve(ans)) continue;
else ans += powfunc(i);
}
cout << ans;
}
# | 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... |