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 <iostream>
#include <cstring>
using namespace std;
using ll = long long;
const int N = 100;
int n, a, b;
ll x[N + 5];
bool vis[N + 5][N + 5][N + 5], using_cuts[N + 5];
bool isSubmask(ll sup, ll sub) {
return (sup | sub) == sup;
}
void brutus(int l, int r, int cuts, ll c) {
if (r == n) using_cuts[cuts] |= isSubmask(c, x[r] - x[l - 1]);
else if (vis[l][r][cuts]) return;
else {
vis[l][r][cuts] = 1;
brutus(l, r + 1, cuts, c);
if (isSubmask(c, x[r] - x[l - 1])) brutus(r + 1, r + 1, cuts + 1, c);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (n > N) exit(0);
cin >> n >> a >> b;
x[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> x[i];
x[i] += x[i - 1];
}
ll c = (1ll << 40) - 1;
for (ll bit = 39; bit >= 0; bit--) {
c -= (1ll << bit);
memset(vis, 0, sizeof vis);
memset(using_cuts, 0, sizeof using_cuts);
brutus(1, 1, 1, c);
bool ok = 0;
for (int i = a; i <= b; i++) {
ok |= using_cuts[i];
}
if (not ok) c += (1ll << bit);
}
cout << c << '\n';
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... |