Submission #205332

#TimeUsernameProblemLanguageResultExecution timeMemory
205332kshitij_sodaniBali Sculptures (APIO15_sculpture)C++17
100 / 100
118 ms504 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl "\n" int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); llo n,a,b; cin>>n>>a>>b; llo it[n]; for(llo i=0;i<n;i++){ cin>>it[i]; } if(n<=100){ llo dp[n][n]; llo ans=0; memset(dp,0,sizeof(dp)); llo pre[n]; pre[0]=it[0]; for(llo i=1;i<n;i++){ pre[i]=pre[i-1]+it[i]; } for(llo i=38;i>=0;i--){ memset(dp,0,sizeof(dp)); //cout<<ans<<endl; ans=ans+(((llo)1<<(i))-(llo)1); // cout<<i<<endl; //cout<<ans<<endl; for(llo j=0;j<n;j++){ for(llo k=0;k<min(j+1,b);k++){ if(k==0){ llo no=pre[j]; no|=ans; if(no==ans){ dp[j][k]=1; } continue; } for(llo l=0;l<j;l++){ llo no=(pre[j]-pre[l]); no|=ans; if(dp[l][k-1]==1 and (no==ans)){ dp[j][k]=1; } } } } ans-=(llo)(((llo)1<<(i))-(llo)1); //cout<<ans<<endl<<endl; llo st=1; for(llo j=a-1;j<b;j++){ if(dp[n-1][j]==1){ st=0; break; } } //cout<<i<<" "<<st<<endl; if(st){ ans|=((llo)1<<i); } } cout<<ans<<endl; } else{ llo dp[n]; llo ans=0; memset(dp,0,sizeof(dp)); llo pre[n]; pre[0]=it[0]; for(llo i=1;i<n;i++){ pre[i]=pre[i-1]+it[i]; } for(llo i=42;i>=0;i--){ memset(dp,0,sizeof(dp)); //cout<<ans<<endl; ans=ans+(((llo)1<<(i))-(llo)1); // cout<<i<<endl; //cout<<ans<<endl; for(llo j=0;j<n;j++){ llo no=pre[j]; no|=ans; if(no==ans){ dp[j]=1; } for(llo l=0;l<j;l++){ llo no=(pre[j]-pre[l]); no|=ans; if(dp[l]>0 and (no==ans)){ if(dp[j]==0){ dp[j]=dp[l]+1; } dp[j]=min(dp[j],dp[l]+1); } } } ans-=(llo)(((llo)1<<(i))-(llo)1); //cout<<ans<<endl<<endl; llo st=1; for(llo j=n-1;j<n;j++){ if(dp[j]>0 and dp[j]<b+1){ st=0; break; } } if(st){ ans|=((llo)1<<i); } } cout<<ans<<endl; } /*llo nno=8|3; //cout<<nno<<endl; */ return 0; }
#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...