Submission #1069095

#TimeUsernameProblemLanguageResultExecution timeMemory
1069095LuvidiBali Sculptures (APIO15_sculpture)C++17
100 / 100
104 ms608 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back void solve() { int n,l,r; cin>>n>>l>>r; ll a[n+1]; for(int i=1;i<=n;i++)cin>>a[i]; if(l==1){ ll ans=(1LL<<41)-1; for(int x=40;x>-1;x--){ ans^=1LL<<x; int dp[n+1]; dp[0]=0; for(int i=1;i<=n;i++){ dp[i]=1e9; ll s=0; for(int j=i;j;j--){ s+=a[j]; if((s&ans)==s){ dp[i]=min(dp[i],dp[j-1]+1); } } } if(dp[n]>r)ans^=1LL<<x; } cout<<ans; }else{ ll ans=(1LL<<41)-1; for(int x=40;x>-1;x--){ ans^=1LL<<x; bool dp[n+1][n+1]; memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=1;i<=n;i++){ for(int k=1;k<=n;k++){ ll s=0; for(int j=i;j;j--){ s+=a[j]; if((s&ans)==s){ dp[i][k]|=dp[j-1][k-1]; } } } } bool s=0; for(int i=l;i<=r;i++)s|=dp[n][i]; if(!s)ans^=1LL<<x; } cout<<ans; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#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...