# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
205433 | anonymous | Bali Sculptures (APIO15_sculpture) | C++14 | 130 ms | 760 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<iostream>
#define MAXN 2005
#define LL long long
using namespace std;
int N, A, B, Y[MAXN];
int dp2[MAXN];
bool dp1[MAXN][MAXN];
LL bits = (1LL << 41) - 1LL, Sum[MAXN];
void case1() { //N <= 100
for (int b = 40; b >= 0; b--) {
bits -= (1LL << b);
dp1[0][0]=1;
for (int i=1; i<=N; i++) {
for (int j=1; j<=N; j++) {
dp1[i][j]=0;
}
}
for (int k=1; k<=N; k++) {
for (int n=1; n<=N; n++) {
for (int j=0; j<n; j++) {
if (((Sum[n] - Sum[j]) | bits) == bits) {
dp1[n][k]|=dp1[j][k-1];
}
}
}
}
bool good = false;
for (int i=A; i<=B; i++) {
good |= dp1[N][i];
}
if (!good) {bits += (1LL << b);}
}
printf("%lld", bits);
}
void case2() { //N <= 2000
for (int b = 40; b >= 0; b--) {
bits -= (1LL << b);
for (int i=1; i<=N; i++) {
dp2[i]=1<<30;
}
for (int n=1; n<=N; n++) {
for (int j=0; j<n; j++) {
if (((Sum[n] - Sum[j]) | bits) == bits) {
dp2[n]=min(dp2[n], dp2[j] + 1);
}
}
}
if (dp2[N] > B) {bits += (1LL << b);}
}
printf("%lld", bits);
}
int main() {
//freopen("balin.txt","r",stdin);
scanf("%d %d %d",&N,&A,&B);
for (int i=1; i<=N; i++) {
scanf("%d",&Y[i]);
Sum[i]=Sum[i-1] + Y[i];
}
if (A == 1) {
case2();
} else {
case1();
}
}
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... |