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 FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
const int MAXN = 2100;
const ll INF = (ll)1e17;
int n, a, b;
ll y[MAXN];
ll pref[MAXN];
bool dp[MAXN][MAXN];
bool check (ll mask) {
// cout << " mask = " << mask << endl;
FOR(i, 0, n) FOR(g, 0, n) dp[i][g] = false;
dp[0][0] = true;
FOR(i, 1, n) FOR(g, 1, i) {
FOR(j, g-1, i-1) {
if (!dp[j][g-1]) continue;
ll sum = pref[i]-pref[j];
if (sum & mask) continue;
dp[i][g] = true;
//cout << " i = " << i << " g = " << g << " is true for j = " << j << endl;
break;
}
}
FOR(x, a, b)
if (dp[n][x])
return true;
return false;
}
int main()
{
FAST_IO;
cin >> n >> a >> b;
FOR(i, 1, n) cin >> y[i];
FOR(i, 1, n) pref[i] = pref[i-1] + y[i];
ll ans = 0;
for (ll k = 50; k >= 0; k--) {
ll cur = ans + (1ll<<k) - 1ll;
ll inv = ~cur;
if (!check(inv))
ans += (1ll << k);
}
cout << ans << "\n";
return 0;
}
/*
in:
6 1 3
8 1 2 1 5 4
ans: 11
in:
6 1 6
8 1 2 1 5 4
*/
# | 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... |