# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
846046 | vjudge1 | Bali Sculptures (APIO15_sculpture) | C++17 | 58 ms | 4392 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define task "test"
#define pii pair<int, int>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
void io() {
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
}
const int inf = 1e9;
const int mod = 1e9+7;
const int nmax = 2e3+5;
int n, p, q, dp2[nmax];
ll a[nmax];
bool dp[nmax][nmax];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
io();
cin >> n >> p >> q;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] += a[i-1];
}
ll ans = (1ll << 41) - 1;
if(p == 1) {
for(int t = 40; t >= 0; --t) {
for(int i = 1; i <= n; ++i) dp2[i] = inf;
ans ^= 1ll << t;
for(int i = 1; i <= n; ++i) {
for(int k = 1; k <= i; ++k) {
if((ans | (a[i] - a[k-1])) == ans) {
dp2[i] = min(dp2[i], dp2[k-1] + 1);
}
}
}
if(dp2[n] > q) ans ^= (1ll << t);
}
}
else {
for(int t = 40; t >= 0; --t) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1; ans ^= 1ll << t;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
for(int k = 1; k <= i; ++k) {
if((ans | (a[i] - a[k - 1])) == ans) {
dp[i][j] |= dp[k-1][j-1];
}
}
}
}
bool ok = 0;
for(int i = p; i <= q; ++i)
if(dp[n][i] == 1) ok = 1;
if (!ok) ans ^= 1ll<<t;
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |