#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll N, A, B;
vector<ll> V;
vector<ll> PS;
ll sum(ll a, ll b) {
return PS[b+1] - PS[a];
}
bool check(ll x) {
vector<vector<bool>> dp(N+1, vector<bool>(B+1)); // dp[i][# of partitions]
dp[0][0] = true;
for(ll i = 0; i <= N; i++) {
for(ll j = 0; j < i; j++) {
for(ll k = 1; k <= B; k++) {
dp[i][k] = dp[i][k] | (dp[j][k-1] & ((x | sum(j, i-1)) == x));
}
}
}
for(ll k = A; k <= B; k++) {
if (dp[N][k]) return dp[N][k];
}
return false;
}
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> N >> A >> B;
V.resize(N), PS.resize(N+1);
ll UB = 0;
for(ll i = 0; i < N; i++) {
cin >> V[i];
PS[i+1] = PS[i] + V[i];
UB += V[i];
}
UB = __lg(UB);
ll cur = (1ll << UB+1ll) - 1ll;
for(ll k = UB; k >= 0; k--) {
if (check(cur ^ (1 << k))) cur ^= (1 << k);
}
cout << cur << endl;
}
| # | 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... |