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;
typedef pair<int, int> ii;
unordered_map<int, ll> dp[110][110];
int a[110], p[110], n;
ll f(int i, int k, int o) {
if(k > i) return 1e18;
if(k == 1) return p[i] | o;
if(dp[i][k].count(o))
return dp[i][k][o];
ll ret = 1e18;
ll sum = a[i];
for(int j = i - 1; j >= 1; j--) {
ret = min(ret, f(j, k - 1, sum | o) | sum | o);
sum += a[j];
}
return dp[i][k][o] = ret;
}
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int n, l, r;
cin >> n >> l >> r;
for(int i = 1; i <= n; i++) {
cin >> a[i]; p[i] = p[i - 1] + a[i];
}
ll ans = 1e18;;
for(int i = l; i <= r; i++) {
ans = min(ans, f(n, i, 0));
}
cout << ans << 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... |