# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397854 | juggernaut | Bali Sculptures (APIO15_sculpture) | C++17 | 20 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>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
#define printl(args...)printf(args)
#else
#define printl(args...)((void)0)
#endif
int n,l,r,a[2005];
ll ans,pref[2005];
bool check(int a,int b){return(((a>>b)|ans)==ans);}
int main(){
scanf("%d%d%d",&n,&l,&r);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
if(n<=100){
for(int bit=45;bit>=0;bit--){
vector<bitset<2005>>dp(n+5);
dp[0]=1;
for(int j=1;j<=n;j++){
ll sum=0;
for(int k=j-1;k>=0;k--){
sum+=a[k];
if(((sum>>(bit+1))|ans)==ans&&!((sum>>bit)&1))dp[j]|=dp[k]<<1;
}
}
bool flag=false;
for(int i=l;i<=r;i++)flag|=dp[n][i];
ans<<=1;
ans|=(!flag);
}
}else{
vector<ll>dp(n+5);
for(int i=1;i<=n;i++)pref[i]=pref[i-1]+a[i-1];
for(int bit=45;bit>=0;bit--){
for(int i=1;i<=n;i++)dp[i]=2e9;
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++)if(check(pref[i]-pref[j],bit+1))umin(dp[i],dp[j]+1);
}
ans<<=1;
ans+=(dp[n]>r);
}
}
printf("%lld",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... |