# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115682 | suzy | Bali Sculptures (APIO15_sculpture) | C++17 | 94 ms | 19072 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>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli a[2001], p[2001];
int n, L, R;
vector<int> con[2001], tmp[2001];
int d1[101][101], d2[2001];
int f1(int c, int k) {
if(k>n) return L<=c && c<=R;
if(d1[c][k]>=0) return d1[c][k];
for(int i=0;i<con[k].size();i++) {
int v=con[k][i];
if(f1(c+1,v+1)) return d1[c][k]=1;
}
return d1[c][k]=0;
}
int f2(int k) {
if(k>n) return 0;
if(d2[k]>=0) return d2[k];
int ret=(1<<30);
for(int i=0;i<con[k].size();i++) {
int v=con[k][i];
ret=min(ret,f2(v+1)+1);
}
return d2[k]=ret;
}
void make(int b) {
for(int i=1;i<=n;i++) {
tmp[i]=con[i];
con[i].clear();
for(int j=0;j<tmp[i].size();j++) {
if((p[tmp[i][j]]-p[i-1])&(1LL<<b)) continue;
con[i].push_back(tmp[i][j]);
}
}
}
lli solve1() {
lli ret=0;
for(int b=41;b>=0;b--) {
memset(d1,-1,sizeof(d1));
make(b);
if(f1(0,1)==0) {
for(int i=1;i<=n;i++)
con[i]=tmp[i];
ret|=(1LL<<b);
}
}
return ret;
}
lli solve2() {
lli ret=0;
for(int b=41;b>=0;b--) {
memset(d2,-1,sizeof(d2));
make(b);
if(f2(1)>R) {
for(int i=1;i<=n;i++)
con[i]=tmp[i];
ret|=(1LL<<b);
}
}
return ret;
}
int main() {
scanf("%d %d %d",&n,&L,&R);
for(int i=1;i<=n;i++) {
scanf("%lld",&a[i]);
p[i]=p[i-1]+a[i];
}
for(int i=1;i<=n;i++) {
for(int j=i;j<=n;j++)
con[i].push_back(j);
}
lli res;
if(L>1) res=solve1();
else res=solve2();
printf("%lld\n",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... |