# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43252 | trungpro | Bali Sculptures (APIO15_sculpture) | C++14 | 94 ms | 812 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>
#define LL long long
using namespace std;
const int N = 2005;
LL sum[N],ans;
bool f[N][N];
int dp[N],n,a,b;
bool sub1(LL mask) {
dp[0] = 0;
for (int i = 1 ; i <= n ; ++ i) {
dp[i] = b + 1;
for (int j = i - 1 ; j >= 0 ; -- j) {
if (((sum[i] -sum[j]) & ~mask) == 0)
dp[i] = min(dp[i],dp[j]+1);
}
}
return (dp[n] <= b);
}
bool sub2(LL mask) {
f[0][0] = 1;
for (int i = 1 ; i <= b ; ++ i)
f[0][i] = 0;
for (int i = 1 ; i <= n ; ++ i) {
f[i][0] = 0;
for (int j = 1 ; j <= b ; ++ j) {
f[i][j] = 0;
for (int k = 0 ; k < i ; ++ k)
if (f[k][j-1] && ((sum[i] - sum[k]) & ~mask) == 0)
f[i][j] = 1;
}
}
for (int i = a; i <= b ; ++ i)
if (f[n][i])
return 1;
return 0;
}
bool check(LL mask) {
if (a == 1)
return sub1(mask);
return sub2(mask);
return 1;
}
int main() {
//freopen(".inp","r",stdin);
//freopen(".out","w",stdout);
scanf("%d%d%d",&n,&a,&b);
for (int i = 1 ; i <= n ; ++ i) {
int val;
scanf("%d",&val);
sum[i] = sum[i-1] +(LL) val;
}
LL ans = (1LL << 41) - 1;
for (int h = 40 ; h >= 0 ; -- h) {
if (check(ans & (~(1LL << h))))
ans &= ~(1LL << h);
// cout << ans << endl;
}
printf("%lld",ans);
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... |