#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,sse4,sse4.2,lzcnt,popcnt")
using ll = long long;
const int INF = 1e9;
const int MXN = 2002;
const int LOG = 41;
int n, A, B;
ll ps[MXN];
namespace n2log {
int dis[MXN];
ll val;
bool check() {
fill(dis+1, dis+n+1, INF);
for(int i=0; i<n; i++)
for(int j=i+1; j<=n; j++)
if(!((ps[j]-ps[i])&val))
dis[j] = min(dis[j], dis[i]+1);
return dis[n]<=B;
}
void solve() {
ll ans=0;
for(int i=LOG-1; i>=0; i--) {
val ^= 1ll<<i;
if(!check())
val ^= 1ll<<i,
ans ^= 1ll<<i;
}
cout << ans << '\n';
}
}
namespace n3log {
const int MXN = 102;
const int LOG = 37;
bool dp[MXN][MXN];
ll val;
bool check() {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i=0; i<n; i++)
for(int x=0; x<B; x++)
if(dp[i][x])
for(int j=i+1; j<=n; j++)
if(!((ps[j]-ps[i])&val))
dp[j][x+1] = 1;
for(int x=A; x<=B; x++)
if(dp[n][x])
return 1;
return 0;
}
void solve() {
ll ans=0;
for(int i=LOG-1; i>=0; i--) {
val ^= 1ll<<i;
if(!check())
val ^= 1ll<<i,
ans ^= 1ll<<i;
}
cout << ans << '\n';
}
}
int32_t main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> A >> B;
for(int i=1; i<=n; i++) {
cin >> ps[i];
ps[i] += ps[i-1];
}
if(A==1) n2log::solve();
else n3log::solve();
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... |