# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98533 | tincamatei | Bali Sculptures (APIO15_sculpture) | C++14 | 99 ms | 512 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 MAX_N = 2000;
const int MAX_N2 = 100;
int dp1[1+MAX_N];
bool dp2[1+MAX_N2][1+MAX_N2];
int y[1+MAX_N];
long long dodp1(int n, int lim) {
long long rez = 0LL;
for(int l = 41; l >= 0; --l) {
long long allowedSet = (rez | ((1LL << l) - 1));
for(int i = 1; i <= n; ++i) {
long long s = 0LL;
dp1[i] = n + 1;
for(int j = i; j > 0; --j) {
s += y[j];
if((s | allowedSet) == allowedSet)
dp1[i] = min(dp1[i], dp1[j - 1] + 1);
}
}
if(dp1[n] > lim)
rez = (rez | (1LL << l));
}
return rez;
}
long long dodp2(int n, int lim1, int lim2) {
long long rez = 0LL;
for(int l = 41; l >= 0; --l) {
long long allowedSet = (rez | ((1LL << l) - 1));
dp2[0][0] = true;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
long long s = 0LL;
dp2[i][j] = false;
for(int k = j; k > 0; --k) {
s += y[k];
if((s | allowedSet) == allowedSet)
dp2[i][j] |= dp2[i - 1][k - 1];
}
}
}
bool ok = false;
for(int i = lim1; i <= lim2; ++i)
if(dp2[i][n])
ok = true;
if(!ok)
rez = (rez | (1LL << l));
}
return rez;
}
int main() {
#ifdef HOME
FILE *fin = fopen("input.in", "r");
FILE *fout = fopen("output.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int n, a, b;
fscanf(fin, "%d%d%d", &n, &a, &b);
for(int i = 1; i <= n; ++i)
fscanf(fin, "%d", &y[i]);
if(a == 1)
fprintf(fout, "%lld", dodp1(n, b));
else
fprintf(fout, "%lld", dodp2(n, a, b));
#ifdef HOME
fclose(fin);
fclose(fout);
#endif
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... |