제출 #344246

#제출 시각아이디문제언어결과실행 시간메모리
344246aZvezdaBali Sculptures (APIO15_sculpture)C++14
100 / 100
139 ms640 KiB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define out(x) "{" << (#x) << ": " << x << "} "

const ll MAX_N = 2e3 + 10;
ll dp1[MAX_N];
ll arr[MAX_N], n, a, b;
bool dp2[MAX_N][MAX_N];

bool pos1(ll mask) {
	for(ll i = 1; i <= n; i ++) {
		dp1[i] = mod;
		for(ll j = i - 1; j >= 0; j --) {
			if(((arr[i] - arr[j]) & mask) == (arr[i] - arr[j])) {
				chkmin(dp1[i], dp1[j] + 1);
			}
		}
	}
	return dp1[n] <= b;
}

bool pos2(ll mask) {
	dp2[0][0] = true;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= n; j ++) {
			dp2[i][j] = false;
			for(int k = i - 1; k >= 0; k --) {
				if(((arr[i] - arr[k]) & mask) == (arr[i] - arr[k])) {
					dp2[i][j] |= dp2[k][j - 1];
				}
			}
		}
	}
	for(int i = a; i <= b; i ++) {
		if(dp2[n][i]) {
			return true;
		}
	}
	return false;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> a >> b;
	for(ll i = 1; i <= n; i ++) {
		cin >> arr[i];
		arr[i] += arr[i - 1];
	}
	if(a == 1) {
		ll mask = (1ll << 51) - 1ll;
		for(ll bit = 50; bit >= 0; bit --) {
			if(pos1(mask ^ (1ll << bit))) {
				mask ^= (1ll << bit);
			}
		}
		cout << mask << endl;
	} else {
		ll mask = (1ll << 51) - 1ll;
		for(ll bit = 50; bit >= 0; bit --) {
			if(pos2(mask ^ (1ll << bit))) {
				mask ^= (1ll << bit);
			}
		}
		cout << mask << 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...