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>
#define ll long long
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
int y[n + 1];
ll pref[n + 1];
pref[0] = 0;
for(int i = 1; i <= n; ++i)
cin >> y[i], pref[i] = pref[i - 1] + y[i];;
// a = 1 -> size only from 1...b
// else -> brute force every size
ll notchosen = 0, chosen = 0;
for(int i = 63; i >= 0; --i) {
// create partition where sum of everything does not have ith bit on and still conforms to previous selected
// try create partition without 1 << i, in
int dp[n + 1];
fill(dp, dp + n + 1, 1e9);
dp[0] = 0;
for(int j = 1; j <= n; ++j) {
for(int k = 1; k <= j; ++k) {
if(!((pref[j] - pref[k - 1]) & (notchosen | (1ll << i)))) {
dp[j] = min(dp[j], dp[k - 1] + 1);
}
}
}
if(dp[n] <= b)
notchosen += 1ll << i;
else
chosen += 1ll << i;
}
cout << chosen << endl;
}
# | 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... |