제출 #344243

#제출 시각아이디문제언어결과실행 시간메모리
344243aZvezdaBali Sculptures (APIO15_sculpture)C++14
50 / 100
119 ms512 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 dp[MAX_N];
ll arr[MAX_N], n, a, b;

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

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];
	}
	ll mask = (1ll << 51) - 1ll;
	for(ll bit = 50; bit >= 0; bit --) {
		if(pos(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...