# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
649187 | ParsaS | Bali Sculptures (APIO15_sculpture) | C++14 | 144 ms | 524 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.
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define int ll
const int N = 2000 + 5, MOD = 1e9 + 7;
int n, a[N], A, B;
int dp[N];
bool dp2[N][N];
void solve() {
if (n <= 100)
return;
ll ans = 0;
int C = 46;
for (int i = 0; i <= C; i++)
ans ^= 1LL << i;
for (int l = C; l >= 0; l--) {
ans ^= 1LL << l;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
ll sum = 0;
dp[i] = n + 1;
for (int j = i; j >= 1; j--) {
sum += a[j];
if ((sum & ans) == sum) {
dp[i] = min(dp[i], dp[j - 1] + 1);
}
}
}
if (dp[n] > B)
ans ^= 1LL << l;
}
cout << ans << '\n';
}
void solve2() {
if (n > 100)
return;
ll ans = 0;
int C = 45;
for (int i = 0; i <= C; i++)
ans ^= 1LL << i;
for (int l = C; l >= 0; l--) {
ans ^= 1LL << l;
dp2[0][0] = true;
for (int j = 1; j <= B; j++) {
for (int i = 1; i <= n; i++) {
dp2[i][j] = false;
ll sum = 0;
for (int k = i; k >= 1; k--) {
sum += a[k];
if ((sum & ans) == sum) {
dp2[i][j] |= dp2[k - 1][j - 1];
}
}
}
}
bool ok = false;
for (int j = A; j <= B; j++)
ok |= dp2[n][j];
if (!ok)
ans ^= 1LL << l;
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++)
cin >> a[i];
solve();
solve2();
return 0;
}
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... |