# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43660 | top34051 | Bali Sculptures (APIO15_sculpture) | C++14 | 131 ms | 1444 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 maxn = 2e3 + 5;
const long long inf = 2e16 + 5;
int n,a,b;
int p[maxn];
int dp1[maxn], dp2[maxn][maxn];
bool check1(long long bit) {
// printf("check %lld\n",bit);
for(int x=1;x<=n;x++) {
long long cur = 0;
dp1[x] = n+1;
for(int y=x;y>=1;y--) {
cur += p[y];
if((cur|bit) == bit) dp1[x] = min(dp1[x], dp1[y-1] + 1);
}
// printf("\tdp %d = %d\n",x,dp[x]);
}
return dp1[n]<=b;
}
bool check2(long long bit) {
// printf("check %lld\n",bit);
dp2[0][0] = 1;
for(int x=1;x<=n;x++) {
for(int k=1;k<=n;k++) {
dp2[x][k] = 0;
long long cur = 0;
for(int y=x;y>=1;y--) {
cur += p[y];
if((cur|bit) == bit) dp2[x][k] |= dp2[y-1][k-1];
}
}
}
for(int k=a;k<=b;k++) if(dp2[n][k]) return 1;
return 0;
}
bool check(long long bit) {
if(a==1) return check1(bit);
return check2(bit);
}
int main() {
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++) scanf("%d",&p[i]);
long long res = (1LL<<41)-1;
for(int i=40;i>=0;i--) {
if(check(res-(1LL<<i))) res -= (1LL<<i);
}
printf("%lld",res);
}
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... |