//Huyduocdithitp
#include <bits/stdc++.h>
typedef long long ll;
#define int long long
#define endl '\n'
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define fi first
#define se second
#define pii pair<ll, ll>
#define inf 1e18
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MP make_pair
#define TASK "ghuy4g"
#define start if(fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);}
#define LOG 46
#define N 2005
using namespace std;
ll onbit(ll mask, ll i) {
return mask | (1LL << i);
}
ll getbit(ll mask, ll i) {
return (mask >> i) & 1LL;
}
ll gb(ll mask1, ll mask2, ll i) {
return (mask1 >> i) | (mask2 >> i);
}
ll n, L, R;
ll a[N], dp[N][N], pf[N];
ll ans;
vector<ll> vtnew[N], vt[N];
signed main(void) {
faster;
cin >> n >> L >> R;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
pf[i] = pf[i - 1] + a[i];
}
for (int bit = LOG; bit >= 0; bit --) {
for (int i = 0; i < N; i ++) {
for (int j = 0; j < N; j ++) {
dp[i][j] = 0;
}
}
vt[0].push_back(0);
dp[0][0] = 1;
for (int k = 1; k <= R; k ++) {
/*for (int i = 1; i <= n; i ++) {
for (int j = i - 1; j >= 0; j --) {
if (dp[j][k - 1]) {
ll xet = pf[i] - pf[j];
//cout << bit << " " << k << " " << i << " " << j << " " << xet << endl;
if (gb(xet, ans, bit) == (ans >> bit)) {
dp[i][k] = 1;
}
}
}
}*/
for (int i = 1; i <= n; i ++) {
for (auto j : vt[k - 1]) {
if (j >= i) break;
if (dp[j][k - 1] && !dp[i][k]) {
ll xet = pf[i] - pf[j];
//cout << bit << " " << i << " " << "prev: " << j << endl;
//cout << bit << " " << k << " " << i << " " << j << " " << xet << endl;
if (gb(xet, ans, bit) == (ans >> bit)) {
dp[i][k] = 1;
vt[k].push_back(i);
break;
}
}
}
}
}
bool ok = 0;
for (int k = L; k <= R; k ++) {
if (dp[n][k]) {
ok = 1;
break;
}
}
if (!ok) {
ans = onbit(ans, bit);
//cout << "bit: " << bit << endl;
}
else {
}
for (int i = 0; i <= R; i ++) {
vt[i].clear();
}
}
cout << ans;
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... |