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;
using ll = long long;
#define all(v) (v).begin(), (v).end()
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, A, B;
cin >> n >> A >> B;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
ll ans = (1LL << 40) - 1;
for (int z = 39; z >= 0; z--) {
ans -= (1LL << z);
ll sm = 0;
vector<int> dp(n, INT_MAX);
for (int i = 0; i < n; i++) {
sm += a[i];
if ((ans & sm) == sm) dp[i] = 0;
ll sm = 0;
for (int k = i; k > 0; k--) {
sm += a[k];
if (dp[k - 1] != INT_MAX && (ans & sm) == sm) dp[i] = min(dp[i], dp[k - 1] + 1);
}
}
if (B <= dp[n - 1]) ans += 1LL << z;
}
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... |