# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238879 | thtsshz_bgwrswh | Bali Sculptures (APIO15_sculpture) | C++17 | 5 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.
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
long long num[2005],n,a,b;
bool check(long long v){
long long i,cnt=0;
for(i=0;i<n;){
long long index=i,ans=num[i];
cnt++;
if(ans>v)
return 0;
while(index+1<n&&num[index+1]+ans<=v){
index++;
ans+=num[index+1];
}
i=index+1;
}
return (cnt<=b);
}
bool check2(long long v,long long pos){
long long i,cnt=0;
for(i=0;i<n;){
long long index=i,ans=num[i];
cnt++;
if(ans>v||((num[index+1]+ans)>>pos)&1)
return 0;
while(index+1<n&&num[index+1]+ans<=v&&!(((num[index+1]+ans)>>pos)&1)){
index++;
ans+=num[index+1];
}
i=index+1;
}
return (cnt<=b);
}
int main(){
long long i;
scanf("%lld%lld%lld",&n,&a,&b);
for(i=0;i<n;i++)
scanf("%lld",&num[i]);
for(i=0;i<45;i++)
if(check((1<<(i+1))-1))
break;
long long ans=(1<<(i+1))-1;
for(;i>=0;i--){
if(check2(ans^(1<<i),i))
ans^=(1<<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... |