Submission #47966

#TimeUsernameProblemLanguageResultExecution timeMemory
47966WA_TLEBali Sculptures (APIO15_sculpture)C++14
100 / 100
75 ms2668 KiB
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
//17:53~
int main(void){
	int n,i,j,A,B;cin>>n>>A>>B;
	vector<llint>y(n);
	vector<llint>wa(n+1);
	for(i=0;i<n;i++){cin>>y[i];}
	for(i=1;i<=n;i++){wa[i]=y[i-1]+wa[i-1];}
	//上のビットから立つかどうかを決める
	//するとこの区間をとってよいかどうかが決まる
	//A=1ならcanまでの最小値を求めていけばいい
	//A>1ならbitsetを持たせる
	//2^41にならない
	if(A==1){
		llint ans=(1LL<<41)-1;
		vector<int>sai(n+1);
		for(int h=40;h>=0;h--){
			ans-=(1LL<<h);
			for(i=0;i<=n;i++){sai[i]=mod;}
			sai[0]=0;
			for(i=1;i<=n;i++){
				for(j=0;j<i;j++){
					if(((wa[i]-wa[j])|ans)==ans){
						mineq(sai[i],sai[j]+1);
					}
				}
			}
			//cout<<sai[n]<<endl;
			ans+=(1LL<<h);
			if(sai[n]<=B){ans-=(1LL<<h);}
		}
		cout<<ans<<endl;
	}else{
		llint ans=(1LL<<41)-1;
		vector<bitset<101>>sai(n+1);
		bitset<101>kara;
		for(int h=40;h>=0;h--){
			ans-=(1LL<<h);
			for(i=0;i<=n;i++){sai[i]=kara;}
			sai[0][0]=1;
			for(i=1;i<=n;i++){
				for(j=0;j<i;j++){
					if(((wa[i]-wa[j])|ans)==ans){
						sai[i]|=(sai[j]<<1);
					}
				}
			}
			ans+=(1LL<<h);
			for(i=A;i<=B;i++){
				if(sai[n][i]){ans-=(1LL<<h);break;}
			}
		}
		cout<<ans<<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...