# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404976 | Hazem | Bali Sculptures (APIO15_sculpture) | C++14 | 137 ms | 336 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;
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
const int N = 2e5+10;
const int M = 3e2+10;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;
LL a[N],dp[N];
bool dp1[M][M];
int n,l,r;
bool check1(LL val){
dp[0] = 0;
for(int i=1;i<=n;i++){
dp[i] = LINF;
LL sum = 0;
for(int j=i;j>=1;j--){
sum += a[j];
if((sum&val)==sum)
dp[i] = min(dp[i],dp[j-1]+1);
}
}
return dp[n]<=r;
}
bool check2(LL val){
dp1[0][0] = 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=i;j++){
LL sum = 0;
dp1[i][j] = 0;
for(int k=i;k>=1;k--){
sum += a[k];
if((sum&val)==sum)
dp1[i][j] |= dp1[k-1][j-1];
}
}
bool q = 0;
for(int i=l;i<=r;i++)
q |= dp1[n][i];
return q;
}
int main(){
//freopen("out.txt","w",stdout);
scanf("%d%d%d",&n,&l,&r);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
LL ans = (1ll<<45)-1;
for(LL i=44;i>=0;i--){
ans ^= 1ll<<i;
if(l==1){
if(!check1(ans))ans ^= 1ll<<i;
}
else
if(!check2(ans))ans ^= 1ll<<i;
}
printf("%lld\n",ans);
}
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... |