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>
//#pragma GCC optimize("O2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
int n, a, b;
const int N = 2e3 + 5;
int arr[N];
void init() {
}
void input() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
}
bool check(ll mask) {
if (n <= 100) {
bitset<N> dp[n + 1];
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
ll sum = 0;
for (int j = i; j >= 1; j--) {
sum += arr[j];
if ((sum & mask) == sum) {
dp[i] |= (dp[j - 1] << 1);
}
}
}
for (int i = a; i <= b; i++) {
if (dp[n][i]) {
return true;
}
}
return false;
}
else {
int ans[n + 1];
ans[0] = 0;
for (int i = 1; i <= n; i++) {
ans[i] = b + 1;
ll sum = 0;
for (int j = i; j >= 1; j--) {
sum += arr[j];
if ((sum & mask) == sum) {
ans[i] = min(ans[i], ans[j - 1] + 1);
}
}
}
return (ans[n] <= b);
}
}
void solve() {
ll mini = (1ll << 50) - 1;
for (int i = 49; i >= 0; i--) {
mini ^= (1ll << i);
if (!check(mini)) {
mini ^= (1ll << i);
}
}
cout << mini;
}
void output() {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int number_of_testcases = 1;
//cin >> number_of_testcases;
while (number_of_testcases--) {
init();
input();
solve();
output();
}
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... |