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;
#define int long long
namespace sub4 {
const int N = 100;
int prefix[N + 5];
bool dp[N + 5][N + 5];
int ans = 0;
void main(int n, int a, int b, int arr[]) {
for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + arr[i];
for (int bit = 40; bit >= 0; bit--) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = false;
}
}
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= i; k++) {
int v = prefix[i] - prefix[k - 1];
if (((v >> bit) | (ans >> bit)) != (ans >> bit)) continue;
dp[i][j] |= dp[k - 1][j - 1];
}
}
}
bool valid = false;
for (int j = a; j <= b; j++) valid |= dp[n][j];
if (!valid) ans ^= (1ll << bit);
}
cout << ans << '\n';
}
}
namespace sub5 {
const int N = 2000;
int dp[N + 5], prefix[N + 5], ans = 0;
void main(int n, int a, int b, int arr[]) {
for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + arr[i];
for (int bit = 45; bit >= 0; bit--) {
for (int i = 0; i <= n; i++) dp[i] = 1e18;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
int v = prefix[i] - prefix[j - 1];
if (((v >> bit) | (ans >> bit)) != (ans >> bit)) continue;
dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
if (dp[n] > b) ans ^= (1ll << bit);
}
cout << ans << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
int arr[n + 5];
for (int i = 1; i <= n; i++)cin >> arr[i];
if (n <= 100) sub4::main(n, a, b, arr);
else sub5::main(n, a, b, arr);
return 0;
}
# | 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... |