제출 #972754

#제출 시각아이디문제언어결과실행 시간메모리
972754GangstaBali Sculptures (APIO15_sculpture)C++14
100 / 100
95 ms608 KiB
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define sz size()

const int N = 2e5 + 1;

using namespace std;

int a, b, n, arr[N], dp[N], dp1[105][105];

bool check(ll x){
	for(int i = 1; i <= n; i++) dp[i] = 1e9;
	for(int i = 1; i <= n; i++){
		ll sum = 0;
		for(int j = i; j > 0; j--){
			sum += arr[j];
			if((sum & x) == sum){
				dp[i] = min(dp[i], dp[j-1] + 1);
			}
		}
	}
	return dp[n] <= b;
}

bool kolya(ll x){
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dp1[i][j] = 0;
		}
	}
	dp1[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i; j++){
			ll sum = 0;
			for(int k = i; k > 0; k--){
				sum += arr[k];
				if((sum & x) == sum){
					dp1[i][j] |= dp1[k-1][j-1];
				}
			}
		}
	}
	for(int i = a; i <= b; i++){
		if(dp1[n][i]) return 1;
	}
	return 0;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
    	cin >> arr[i];
    }
    ll x = (1LL<<42)-1;
    for(int i = 41; i >= 0; i--){
    	x -= (1LL<<i);
    	if(a == 1 and !check(x)) x += (1LL<<i);
    	else if (a > 1 and !kolya(x)) x += (1LL<<i);
    }
    cout << x << '\n';
}
#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...