제출 #259218

#제출 시각아이디문제언어결과실행 시간메모리
259218shayan_pBali Sculptures (APIO15_sculpture)C++17
100 / 100
162 ms504 KiB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 110, Max = 2010, mod = 1e9 + 7, Log = 50;

int a[Max], n, L, R;
int dp[Max];
bitset<maxn> bs[maxn];

bool ok(ll deny){
    if(L == 1){
	for(int i = 0; i < n; i++){
	    dp[i + 1] = n + 10;
	    ll sm = 0;
	    for(int j = i; j >= 0; j--){
		sm+= a[j];
		if(sm & deny)
		    continue;
		dp[i + 1] = min(dp[i + 1], 1 + dp[j]);
	    }
	}
	if(dp[n] <= R)
	    return 1;
    }
    else{
	bs[0][0] = 1;
	for(int i = 0; i < n; i++){
	    bs[i + 1] = 0;
	    ll sm = 0;
	    for(int j = i; j >= 0; j--){
		sm+= a[j];
		if(sm & deny)
		    continue;
		bs[i+1] = bs[i+1] | (bs[j]<<1);			
	    }
	}
	for(int i = L; i <= R; i++){
	    if(bs[n][i])
		return 1;
	}
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    cin >> n >> L >> R;
    for(int i = 0; i < n; i++){
	cin >> a[i];
    }
    ll ans = (1ll<<Log) - 1;
    for(int bt = Log-1; bt >= 0; bt--){
	ans^= 1ll<<bt;
	if(ok(((1ll<<Log) - 1) ^ ans) == 0)
	    ans^= 1ll<<bt;	
    }
    return cout << ans << endl, 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...