#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
#define vi vector<long long>
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pr pair<ll, ll>
#define ff first
#define ss second
void solution();
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solution();
return 0;
}
const int N = 2e3+10;
ll a[N];
ll n, A, B;
const int inf = INT_MAX;
ll calculate(int A, int B) {
vi dp[n+1];
for (int i = 0; i <= n; i++) dp[i].resize(B+1, inf);
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= B; j++) {
for (int l = 0; l < i; l++) {
dp[i][j] = min(dp[i][j],(a[i]-a[l])|dp[l][j-1]);
}
}
}
ll ans = inf;
for (int i = A; i <= B; i++) ans = min(ans, dp[n][i]);
return ans;
}
void solution() {
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i-1];
}
cout << calculate(A, B) << 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... |