제출 #671124

#제출 시각아이디문제언어결과실행 시간메모리
671124NothingXDBali Sculptures (APIO15_sculpture)C++17
100 / 100
646 ms94500 KiB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
/*typedef __uint128_t L;
struct FastMod {
  ull b, m;
  FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {}
  ull reduce(ull a) {
    ull q = (ull)((L(m) * a) >> 64);
    ull r = a - q * b; // can be proven that 0 <= r < 2*b
    return r >= b ? r - b : r;
  }
};
FastMod FM(2);*/
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e3 + 10;
const int lg = 42;
const int inf = 1e9;

int n, A, B, a[maxn], dp[maxn][maxn];
ll part[maxn];
set<int> opt[maxn];
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n >> A >> B;

	for (int i = 1; i <= n; i++) cin >> a[i];

	for (int i = 1; i <= n; i++) part[i] = part[i-1] + a[i];

	for (int i = 1; i <= n; i++){
		for (int j = 0; j < i; j++){
			opt[i].insert(j);
		}
	}

	if (A == 1){
		ll ans = 0;
		for (int k = lg - 1; ~k; k--){
			for (int i = 1; i <= n; i++){
				dp[0][i] = inf;
				for (auto x: opt[i]){
					ll tmp = part[i] - part[x];
					if ((tmp >> k) & 1) continue;
					dp[0][i] = min(dp[0][i], dp[0][x] + 1);
				}
			}
			if (dp[0][n] <= B){
				for (int i = 1; i <= n; i++){
					vector<int> del;
					for (auto x: opt[i]){
						ll tmp = part[i] - part[x];
						if ((tmp >> k) & 1) del.push_back(x);
					}
					for (auto x: del){
						opt[i].erase(x);
					}
				}
			}
			else{
				ans += (1ll << k);
			}
		}
		cout << ans << '\n';
		return 0;
	}

	ll ans = 0;

	for (int k = lg - 1; ~k; k--){
		dp[0][0] = 1;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				dp[i][j] = 0;
				for (auto x: opt[j]){
					ll tmp = part[j] - part[x];
					if ((tmp >> k) & 1) continue;
					dp[i][j] = max(dp[i][j], dp[i-1][x]);
				}
			}
		}
		bool flg = false;
		for (int i = A; i <= B; i++){
			if (dp[i][n]) flg = true;
		}
		if (flg){
			for (int i = 1; i <= n; i++){
				vector<int> del;
				for (auto x: opt[i]){
					ll tmp = part[i] - part[x];
					if ((tmp >> k) & 1) del.push_back(x);
				}
				for (auto x: del){
					opt[i].erase(x);
				}
			}
		}
		else{
			ans += (1ll << k);
		}
	}
	cout << ans << '\n';

	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...