# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
671600 | Radin_Zahedi2 | Bali Sculptures (APIO15_sculpture) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
//#pragma gcc optimize("o2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
int n, a, b;
const int n = 2e3 + 5;
int arr[n];
void init() {
}
void input() {
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
}
bool check(ll mask) {
if (n <= 100) {
bitset<n> dp[n + 1];
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
ll sum = 0;
for (int j = i; j >= 1; j--) {
sum += arr[j];
if ((sum & mask) == sum) {
dp[i] |= (dp[j - 1] << 1);
}
}
}
for (int i = a; i <= b; i++) {
if (dp[n][i]) {
return true;
}
}
return false;
}
else {
int ans[n + 1];
ans[0] = 0;
for (int i = 1; i <= n; i++) {
ans[i] = b + 1;
ll sum = 0;
for (int j = i; j >= 1; j--) {
sum += arr[j];
if ((sum & mask) == sum) {
ans[i] = min(ans[i], ans[j - 1] + 1);
}
}
}
return (ans[n] <= b);
}
}
void solve() {
ll mini = (1ll << 50) - 1;
for (int i = 49; i >= 0; i--) {
mini ^= (1ll << i);
if (!check(mini)) {
mini ^= (1ll << i);
}
}
cout << mini;
}
void output() {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int number_of_testcases = 1;
//cin >> number_of_testcases;
while (number_of_testcases--) {
init();
input();
solve();
output();
}
return 0;
}