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;
const long long INF_LL = (1LL << 41) - 1;
void Solve(int n, int a, int b, const vector<int> &v) {
vector<vector<long long>> dp(n + 1, vector<long long>(b + 1, INF_LL));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= b; ++j) {
long long sum = 0LL;
for (int k = i; k >= 1; --k) {
sum += v[k];
dp[i][j] = min(dp[i][j], dp[k - 1][j - 1] | sum);
}
}
}
cout << *min_element(dp[n].begin() + a, dp[n].begin() + b) << endl;
}
void SolveA1(int n, int b, const vector<int> &v) {
vector<int> dp(n + 1);
auto Check = [&](long long mask) {
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
long long sum = 0LL;
dp[i] = n + 1;
for (int j = i; j >= 1; --j) {
sum += v[j];
if ((sum | mask) == mask)
dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
return dp[n] <= b;
};
long long ans = INF_LL;
for (int bit = 40; bit >= 0; --bit) {
if (Check(ans ^ (1LL << bit)))
ans ^= 1LL << bit;
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, a, b; cin >> n >> a >> b;
vector<int> v(n + 1);
for (int i = 1; i <= n; ++i)
cin >> v[i];
if (a == 1) SolveA1(n, b, v);
else Solve(n, a, b, v);
}
# | 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... |