# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
70658 | evpipis | Bali Sculptures (APIO15_sculpture) | C++11 | 112 ms | 1176 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;
typedef long long ll;
const int inf = 1e9;
int dp1[105][105], dp2[2005], n, a, b, arr[2005];
bool solve1(ll x){
dp1[n+1][0] = 1;
for (int i = n; i >= 1; i--)
for (int k = 1; k <= b; k++){
ll sum = 0;
dp1[i][k] = 0;
for (int j = i; j <= n; j++){
sum += arr[j];
if ((sum|x) == x)
dp1[i][k] |= dp1[j+1][k-1];
}
}
for (int k = a; k <= b; k++)
if (dp1[1][k]) return true;
return false;
}
bool solve2(ll x){
for (int i = n; i >= 1; i--){
ll sum = 0;
dp2[i] = inf;
for (int j = i; j <= n; j++){
sum += arr[j];
if ((sum|x) == x)
dp2[i] = min(dp2[i], dp2[j+1]+1);
}
}
return (dp2[1] <= b);
}
int main(){
scanf("%d %d %d", &n, &a, &b);
for (int i = 1; i <= n; i++)
scanf("%d", &arr[i]);
ll ans = (1LL<<41)-1;
for (int j = 40; j >= 0; j--){
if (a != 1 && solve1(ans^(1LL<<j)))
ans ^= (1LL<<j);
if (a == 1 && solve2(ans^(1LL<<j)))
ans ^= (1LL<<j);
}
printf("%lld\n", ans);
return 0;
}
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... |