Submission #540606

#TimeUsernameProblemLanguageResultExecution timeMemory
540606FatihSolakBali Sculptures (APIO15_sculpture)C++17
100 / 100
109 ms552 KiB
#include <bits/stdc++.h> #define N 2005 #define K 50 using namespace std; int arr[N]; int n,a,b; bool dp[N][N]; int dp2[N]; bool ck(long long mask){ if(n <= 100){ for(int i=1;i<=n;i++){ for(int j = 1;j<=n;j++){ dp[i][j] = 0; } } dp[0][0] = 1; for(int i=0;i<n;i++){ for(int j = 0;j<=i;j++){ long long sum = 0; for(int c = i+1;c<=n;c++){ sum += arr[c]; if((sum & mask) == 0){ dp[c][j+1] |= dp[i][j]; } } } } for(int i = a;i<=b;i++){ if(dp[n][i]) return dp[n][i]; } return 0; } else{ for(int i = 1;i<=n;i++){ dp2[i] = 1e9; } for(int i=0;i<n;i++){ long long sum = 0; for(int c = i+1;c<=n;c++){ sum += arr[c]; if((sum & mask) == 0){ dp2[c] = min(dp2[c],dp2[i] + 1); } } } return dp2[n] <= b; } } void solve(){ cin >> n >> a >> b; for(int i=1;i<=n;i++){ cin >> arr[i]; } long long mask = 0; for(int i = K;i>=0;i--){ if(ck(mask | (1ll<<i))){ mask |= (1ll<<i); } } cout << ((1ll<<(K+1)) - 1) - mask; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t=1; //cin>>t; while(t--){ solve(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#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...