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;
typedef long long ll;
const ll MAXN1 = 100;
bool dp[MAXN1+1][MAXN1];
ll n, a, b;
ll vals[MAXN1];
ll cur = 0;
ll bit;
bool works(ll sum) {
ll sumshift = sum >> bit;
ll curshift = cur >> bit;
return (curshift&sumshift) == sumshift;
}
bool possible() {
for (ll i = n; i >= 0; i--) {
for (ll j = 0; j < n; j++) {
dp[i][j] = 0;
if (i == n) {
dp[i][j] = 1;
continue;
}
if (j > n-i) {
dp[i][j] = dp[i][n-i];
continue;
}
if (j == 0) {
continue;
}
ll s = 0;
for (ll next = i+1; next <= n; next++) {
s += vals[next-1];
if (dp[next][j-1] && works(s)) {
dp[i][j] = 1;
break;
}
}
}
}
for (ll i = a; i <= b; i++)
if (dp[0][i]) return 1;
return 0;
}
int main() {
cin >> n >> a >> b;
for (ll i = 0; i < n; i++) {
cin >> vals[i];
cur += vals[i];
}
bit = floor(log2(cur));
cur = 0;
while (bit >= 0) {
if (!possible()) { // possible to avoid
cur += (1ULL << bit);
}
bit--;
}
cout << cur << "\n";
}
# | 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... |