Submission #41697

#TimeUsernameProblemLanguageResultExecution timeMemory
41697HassoonyBali Sculptures (APIO15_sculpture)C++14
100 / 100
172 ms1152 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; const ll inf=(1ll<<61); const int MX=2009; ll n,A,B; ll a[MX],dp[MX],ans,sum1,dp1[109][109]; ll DP(ll x){ if(x==n)return 0; ll &ret=dp[x];if(ret!=-1)return ret; ret=inf; ll sum=0; for(int i=x;i<n;i++){ sum+=a[i]; if((sum&sum1)==0){ ret=min(ret,DP(i+1)+1); } } return ret; } ll DP1(ll x,ll y){ if(y>B)return 0; if(x==n)return (y>=A); ll &ret=dp1[x][y];if(ret!=-1)return ret; ret=0; ll sum=0; for(int i=x;i<n;i++){ sum+=a[i]; if((sum&sum1)==0){ ret=max(ret,DP1(i+1,y+1)); } } return ret; } int main(){ cin>>n>>A>>B; for(int i=0;i<n;i++)scanf("%lld",&a[i]); if(A==1){ for(ll i=48;i>=0;i--){ memset(dp,-1,sizeof(dp)); sum1+=(1ll<<i); if(DP(0)<=B)continue; ans+=(1ll<<i); sum1-=(1ll<<i); } cout<<ans<<endl; return 0; } for(ll i=48;i>=0;i--){ sum1+=(1ll<<i); memset(dp1,-1,sizeof(dp1)); if(DP1(0,0)!=0)continue; ans+=(1ll<<i); sum1-=(1ll<<i); } cout<<ans<<endl; }

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:38:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++)scanf("%lld",&a[i]);
                                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...