# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
952595 | 2024-03-24T10:48:19 Z | Unforgettablepl | Bali Sculptures (APIO15_sculpture) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; #define int long long bool DP[101][101]; int DPmin[2001]; int arr[2001]; int a,b,n; bool testany(int k){ for(auto&i:DP)for(auto&j:i)j=false; DP[0][0]=true; for(int j=1;j<=b;j++){ for(int i=j;i<=n;i++){ int sum = arr[i]; for(int x=i-1;x>=j-1;x--){ if((sum|k) == k and DP[x][j-1]){DP[i][j]=true;break;} sum+=arr[x]; } } } for(int i=a;i<=b;i++)if(DP[n][i])return true; return false; } bool test1(int k){ for(int i=0;i<=n;i++)DPmin[i]=1e18; DPmin[0]=0; for(int i=1;i<=n;i++){ int sum = arr[i]; for(int j=i-1;j>=0;j--){ if((sum|k)==k)DPmin[i]=min(DPmin[i],DPmin[j]+1); sum+=arr[j]; } } return DPmin[n]<=b; } bool can() { REP(i, N+1) dp[i] = INF; dp[0] = 0; REP(i, N) { ll sum = 0; FOR(j, i, N) { sum += D[j]; if ((sum | ans) == ans) dp[j + 1] = min(dp[j + 1], 1 + dp[i]); } } return dp[N] <= B; } bool test(int k){ return n<=100 ? testany(k) : test1(k); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> a >> b; for(int i=1;i<=n;i++)cin>>arr[i]; int ans = 0; for(int bit=57;bit>=0;bit--){ if(test(ans|((1ll<<bit)-1)))continue; ans|=(1ll<<bit); } cout << ans << '\n'; }