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 int N = 2005, M = 105;
int n, a, b;
int64_t pre[N];
bool check1(int64_t cur, int bt) {
vector<int> dp(n + 1, 1e9);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
int64_t f = (pre[i] - pre[j]) >> bt, s = cur >> bt;
if ((f | s) == s) dp[i] = min(dp[i], dp[j] + 1);
}
}
return dp[n] <= b;
}
bool dp[N][N];
bool check(int64_t cur, int bt) {
if (n > 100)
return check1(cur, bt);
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
int64_t f = (pre[i] - pre[j]) >> bt, s = cur >> bt;
if ((f | s) == s) {
for (int k = 1; k <= j + 1; k++)
dp[i][k] |= dp[j][k - 1];
}
}
}
for (int i = a; i <= b; i++)
if (dp[n][i]) return 1;
return 0;
}
signed main() {
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
cin >> n >> a >> b;
for (int i = 1, x; i <= n; i++)
cin >> x, pre[i] = pre[i - 1] + x;
int64_t res = 0;
for (int i = 40; ~i; i--) {
if (!check(res, i))
res |= 1ll << i;
}
cout << res;
}
# | 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... |