제출 #1269389

#제출 시각아이디문제언어결과실행 시간메모리
1269389WH8Bali Sculptures (APIO15_sculpture)C++20
37 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define pll pair<int, int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define endl '\n'

signed main(){
	int n,a,b;cin>>n>>a>>b;
	vector<int> v(n+1, 0), ps(n+1, 0);
	for(int i=1;i<=n;i++){
		cin>>v[i];
		ps[i]=ps[i-1]+v[i];
	}
	int ans=(1<<30)-1;
	for(int i=29;i>=0;i--){
		int check=ans;
		check^=(1<<i); // flip this bit;
		if(a==1){
			vector<int> dp(n+1, 1e9);
			dp[0]=0;
			for(int j=1;j<=n;j++){
				for(int k=0;k<j;k++){
					if(((ps[j]-ps[k]) | check) == check){
						dp[j]=min(dp[j],dp[k]+1);
					}
				}
			}
			if(dp[n] <= b){
				ans=check;
			}
		}
		else {
			vector<vector<bool>> dp(n+1, vector<bool>(n+1, 0));
			dp[0][0]=1;
			for(int j=1;j<=n;j++){
				for(int s=1;s<=n;s++){
					for(int k=0;k<j;k++){
						if(((ps[j]-ps[k]) | check) == check){
							dp[j][s] = dp[j][s] || dp[k][s-1];
						}
					}
				}
			}
			bool pos=0;
			for(int j=a;j<=b;j++){
				pos|=dp[n][j];
			}
			if(pos)ans=check;
		}
	}
	cout<<ans;
}
#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...