Submission #332840

#TimeUsernameProblemLanguageResultExecution timeMemory
332840errorgornBali Sculptures (APIO15_sculpture)C++17
100 / 100
177 ms508 KiB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,l,h;
int arr[2005];
bool memo1[105][105];
int memo2[2005];

bool can1(ll i){
	memset(memo1,false,sizeof(memo1));
	
	memo1[0][0]=true;
	
	rep(x,0,n){
		rep(y,0,n) if (memo1[x][y]){
			ll curr=0;
			rep(z,x,n){
				curr+=arr[z];
				if ((curr&i)==0) memo1[z+1][y+1]=true;
			}
		}
	}
	
	rep(x,l,h+1) if (memo1[n][x]) return true;
	return false;
}

bool can2(ll i){
	memset(memo2,63,sizeof(memo2));
	
	memo2[0]=0;
	
	rep(x,1,n+1){
		ll curr=0;
		rep(y,x,0){
			curr+=arr[y];
			
			if ((curr&i)==0) memo2[x]=min(memo2[x],memo2[y]+1);
		}
	}
	
	return memo2[n]<=h;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>l>>h;
	rep(x,0,n) cin>>arr[x];
	
	ll ans=0;
	ll curr=1LL<<45;
	while (curr){
		if (n<=100){
			if (can1(ans|curr)) ans|=curr;
		}
		else{
			if (can2(ans|curr)) ans|=curr;
		}
		
		curr>>=1;
	}
	
	cout<<(ans^((1LL<<46)-1))<<endl;
}
#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...