This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define debug(x) cerr << #x << ": " << x << endl;
#define kill(x) cout << x << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
int n, l, r;
const int maxn1 = 100 + 4;
const int maxn2 = 2e3 + 4;
const int oo = 1e9;
ll a[maxn2]; ll res = 0;
bool dp[maxn1][maxn1];
int dpx[maxn2];
bool check(int bt) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) dp[i][j] = 0;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
ll val = 0;
for (int j = i; j >= 1; j--) {
val += a[j];
if (((val >> bt) | (res >> bt)) == (res >> bt)) {
for (int k = 1; k <= n; k++) {
dp[i][k] |= dp[j - 1][k - 1];
}
}
}
}
for (int k = l; k <= r; k++) {
if (dp[n][k]) return 1;
}
return 0;
}
bool checkx(int bt) {
for (int i = 0; i <= n; i++) {
dpx[i] = oo;
}
dpx[0] = 0;
for (int i = 1; i <= n; i++) {
ll val = 0;
for (int j = i; j >= 1; j--) {
val += a[j];
if (((val >> bt) | (res >> bt)) == (res >> bt)) {
dpx[i] = min(dpx[i], dpx[j - 1] + 1);
}
}
}
return (dpx[n] <= r);
}
void solve(int bt = 50) {
if (bt < 0) return ;
if (n <= 100) {
if (!check(bt)) res += (1ll << bt);
}
else {
if (!checkx(bt)) res += (1ll << bt);
}
solve(bt - 1);
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> l >> r;
for (int i = 1; i <= n; i++) cin >> a[i];
solve();
cout << res << endl;
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... |