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 int64_t ll;
typedef string str;
const int N = 101;
const int R = 101;
const int Y = 2001;
const ll inf = 1e18;
ll y[N], pref[N];
bool dp[N][R][Y];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
if (n <= 20) {
ll ans = inf;
for (int i = 0; i < n; ++i) {
cin >> y[i];
}
for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
int cnt = __builtin_popcount(mask) + 1;
if (cnt < a || cnt > b) {
continue;
}
ll cur = 0;
ll sum = y[0];
for (int bit = 0; bit < n - 1; ++bit) {
if (mask & (1 << bit)) {
cur |= sum;
sum = y[bit + 1];
} else {
sum += y[bit + 1];
}
}
cur |= sum;
ans = min(ans, cur);
}
cout << ans;
} else {
for (int i = 1; i <= n; ++i) {
cin >> y[i];
pref[i] = pref[i - 1] + y[i];
}
for (int i = 1; i <= n; ++i) {
dp[i][1][pref[i]] = true;
}
for (int k = 2; k <= b; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = i - 1; j >= 1; --j) {
for (int x = 0; x < Y; ++x) {
if (dp[j][k - 1][x]) {
dp[i][k][x | (pref[i] - pref[j])] = true;
}
}
}
}
}
ll ans = inf;
for (int k = a; k <= b; ++k) {
for (int x = 0; x < Y; ++x) {
if (dp[n][k][x]) {
ans = min(ans, (ll)x);
}
}
}
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... |