# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
23427 | 14kg | Bali Sculptures (APIO15_sculpture) | C++11 | 283 ms | 36356 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 <stdio.h>
#define N 2002
#define INF 999999999
#define min2(x,y) (x<y?x:y)
#define max2(x,y) (x>y?x:y)
int n, L, R, nn;
bool out[51], check[N][N];
long long p[51], in[N], s[N][N];
int main()
{
int num, temp1[N], temp2[N];
long long sum, tot=0;
scanf("%d %d %d", &n, &L, &R);
for (int i = 1; i <= n; i++) scanf("%lld", &in[i]);
p[0] = 1;
for (int i = 1; i <= 50; i++) p[i] = p[i - 1] * 2;
for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) s[i][j] = s[i][j - 1] + in[j];
if (s[1][n] == 0) { printf("0"); return 0; }
for (int i = 49; i >= 0; i--)
{
num = 1, sum = 0;
for (int j = 1; j <= n; j++)
{
sum += in[j];
if (sum >= p[i + 1]) sum = in[j], num++;
if (sum >= p[i + 1]) { num = INF; break; }
}
if (num > R) { nn = i + 1; break; }
} out[nn] = true;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++) if (s[i][j] < p[nn + 1]) check[i][j] = true;
for (int i = nn - 1; i >= 0; i--)
{
temp1[1] = 0, temp2[1] = 0;
for (int j = 2; j <= n + 1; j++) temp1[j] = INF, temp2[j] = -INF;
for (int j = 1; j <= n; j++)
for (int t = j; t <= n; t++) if (check[j][t] && (s[j][t] & p[i]) == 0)
temp1[t + 1] = min2(temp1[t + 1], temp1[j] + 1), temp2[t + 1] = max2(temp2[t + 1], temp2[j] + 1);
if (temp1[n + 1] != INF && L <= temp2[n + 1] && temp1[n + 1] <= R)
{
for (int j = 1; j <= n; j++)
for (int t = j; t <= n; t++) if (s[j][t] & p[i]) check[j][t] = false;
}
else out[i] = true;
}
for (int i = nn; i >= 0; i--)
if (out[i]) tot += p[i];
printf("%lld", tot);
}
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... |