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>
#define int long long
using namespace std;
const int NMAX = 2048;
const int INF = 1e18L;
int N, A, B, a[NMAX], dp[NMAX], ans = (1LL << 60) - 1;
void min_self(int &a, int b) {
a = min(a, b);
}
bool check() {
for(int i = 1; i <= N; ++i)
dp[i] = INF;
for(int i = 0; i < N; ++i) {
int sum = 0;
for(int j = i; j < N; ++j) {
sum += a[j];
if((sum | ans) == ans)
min_self(dp[j + 1], dp[i] + 1);
}
}
return dp[N] <= B;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> N >> A >> B;
for(int i = 0; i < N; ++i)
cin >> a[i];
for(int bit = 59; bit >= 0; --bit) {
ans ^= (1LL << bit);
if(!check())
ans |= (1LL << bit);
}
cout << ans << '\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |