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 <stdio.h>
#include <string.h>
#define N 2000
#define H 40
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int solve(int *aa, int n, int l, int r, long long x) {
static int dp[N + 1], dq[N + 1][N + 1];
int i, j, k;
long long sum;
if (l == 1) {
memset(dp, 0x3f, (n + 1) * sizeof *dp);
dp[0] = 0;
for (i = 0; i < n; i++)
if (dp[i] != INF) {
sum = 0;
for (j = i + 1; j <= n; j++) {
sum += aa[j - 1];
if ((x | sum) == x)
dp[j] = min(dp[j], dp[i] + 1);
}
}
return dp[n] <= r;
} else {
for (i = 0; i <= n; i++)
memset(dq[i], 0, (n + 1) * sizeof *dq[i]);
dq[0][0] = 1;
for (i = 0; i < n; i++)
for (k = 0; k < n; k++)
if (dq[i][k]) {
sum = 0;
for (j = i + 1; j <= n; j++) {
sum += aa[j - 1];
if ((x | sum) == x)
dq[j][k + 1] = 1;
}
}
for (k = l; k <= r; k++)
if (dq[n][k])
return 1;
return 0;
}
}
int main() {
static int aa[N];
int n, l, r, h, i;
long long ans;
scanf("%d%d%d", &n, &l, &r);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
ans = (1LL << H + 1) - 1;
for (h = H; h >= 0; h--)
if (solve(aa, n, l, r, ans ^ 1LL << h))
ans ^= 1LL << h;
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
sculpture.c: In function 'main':
sculpture.c:57:13: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
57 | ans = (1LL << H + 1) - 1;
| ^~
sculpture.c:54:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
54 | scanf("%d%d%d", &n, &l, &r);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.c:56:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
56 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | 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... |