제출 #391052

#제출 시각아이디문제언어결과실행 시간메모리
391052BlagojceBali Sculptures (APIO15_sculpture)C++11
71 / 100
1083 ms11468 KiB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)


using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;

mt19937 _rand(time(NULL));
clock_t z;

const int mxn = 2e3+5;

int N, A, B;
int a[mxn];

vector<int> g[mxn];

//bool dp[mxn][mxn];

bitset<mxn> dp[mxn];

bool ok(ll mask){
	fr(i, 0, N){
		g[i+1].clear();
		ll sum = 0;
		for(int j = i; j >= 0; j --){
			sum += a[j];
			if((mask&sum) == sum){
				g[i+1].pb(j+1);
			}
		}
	}
	//memset(dp, false, sizeof(dp));
	fr(i, 0, N+1) dp[i] = 0;
	
	dp[0][0] = 1;
	fr(i, 1, N+1){
		for(auto j : g[i]){
			
			dp[i] |= (dp[j-1]<<1);
			
			/*fr(k, 0, N){
				dp[i][k+1] |= dp[j-1][k];
			}*/
		}
	}
	bool r = false;
	fr(i, A, B+1){
		r |= dp[N][i];
	}
	return r;
}



void solve(){
	cin >> N >> A >> B;
	fr(i, 0, N){
		cin >> a[i];
	}
	ll mask = (1LL<<50)-1;

	
	for(int i = 49; i >= 0; i --){
		mask ^= (1LL<<i);
		if(!ok(mask)){
			mask ^= (1LL<<i);
		}
	}
	cout<<mask<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}

/*
6 1 3
8 1 2 1 5 4

*/
#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...