# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133568 | junodeveloper | Bali Sculptures (APIO15_sculpture) | C++14 | 1016 ms | 648 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 sz(x) (int)x.size()
#define fi first
#define se second
using namespace std;
typedef long long ll;
int n, A, B, D[2010];
ll a[2010];
bool chk[2010][2010];
inline bool f(ll x,ll sum,int p) {
return (~x&sum)/(1ll<<p)==0;
}
bool Check1 (ll x, int p) {
int i,j,k;ll sum;
for(i=1;i<=n;i++) {
chk[i][1]=f(x,a[i],p);
for(j=2;j<=i;j++) {
chk[i][j]=false;
for(k=i-1;k>=j-1;k--) {
sum=a[i]-a[k];
if(f(x,sum,p)) {
chk[i][j]|=chk[k][j-1];
}
}
}
}
bool res=false;
for(i=A;i<=B;i++) res|=chk[n][i];
return res;
}
bool Check2(ll x, int p) {
memset(D,-1,sizeof(D));
queue<int> q;
q.push(n); D[n]=0;
while(!q.empty()) {
int u=q.front(); q.pop();
for(int i=u-1;i>=0;i--) {
if(D[i]==-1 && f(x,a[u]-a[i],p)) {
D[i]=D[u]+1;
q.push(i);
}
}
}
return D[0]!=-1&&D[0]<=B;
}
int main() {
int task;
scanf("%d%d%d",&n,&A,&B);
if(n<=100) task=0;
else task=1;
int i;
for(i=1;i<=n;i++) {
scanf("%lld",a+i);
a[i]+=a[i-1];
}
ll res=0;
for(i=43;i>=0;i--) {
if(task) { if(!Check2(res,i)) res|=1ll<<i; }
else { if(!Check1(res,i)) res|=1ll<<i; }
}
printf("%lld",res);
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... |