# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26256 | szawinis | Bali Sculptures (APIO15_sculpture) | C++14 | 99 ms | 6140 KiB |
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;
const int N = 2001;
const long long INF = 1e18;
int n, a, b, p[N];
long long ans, sum[N], dp[N];
bool check[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) cin >> p[i], sum[i] = sum[i-1] + p[i];
if(a == 1) {
for(int pw = log2(sum[n]); pw >= 0; pw--) {
fill(dp+1, dp+n+1, INF);
for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) {
if(!(sum[i] - sum[j] & (ans | 1ll << pw))) dp[i] = min(dp[j] + 1, dp[i]);
}
if(dp[n] <= b) ans |= 1ll << pw;
}
} else {
for(int pw = log2(sum[n]); pw >= 0; pw--) {
check[0][0] = true;
for(int k = 1; k <= b; k++) {
for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) {
if(!(sum[i] - sum[j] & (ans | 1ll << pw))) check[i][k] |= check[j][k-1];
}
}
for(int k = a; k <= b; k++) if(check[n][k]) {
ans |= 1ll << pw;
break;
}
}
}
cout << (1ll << int(log2(sum[n])+1)) - 1 - ans;
}
Compilation message (stderr)
# | 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... |