# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
654217 | nguyentunglam | Bali Sculptures (APIO15_sculpture) | C++14 | 107 ms | 368 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 forin(i, a, b) for(int i = a; i <= b; i++)
#define forde(i, a, b) for(int i = a; i >= b; i--)
#define forv(a, b) for(auto & a : b)
#define fi first
#define se second
#define ii pair<int, int>
#define endl "\n"
using namespace std;
const int N = 2010;
long long res, s[N];
int f[N], n, a, b;
bool g[110][110];
void sub5() {
for(int bit = 40; bit >= 0; bit--) {
memset(f, 127, sizeof(f));
f[0] = 0;
for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) {
long long sum = s[i] - s[j];
sum >>= bit; sum <<= bit;
if ((res | sum) == res) f[i] = min(f[i], f[j] + 1);
}
if (f[n] > b) res |= (1LL << bit);
}
}
void sub4() {
for(int bit = 40; bit >= 0; bit--) {
memset(g, 0, sizeof(g));
g[0][0] = 1;
for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) {
long long sum = s[i] - s[j];
sum >>= bit; sum <<= bit;
if ((res | sum) == res) for(int k = 1; k <= b; k++) g[i][k] = max(g[i][k], g[j][k - 1]);
}
bool ok = 0;
for(int k = a; k <= b; k++) ok |= g[n][k];
if (!ok) res |= (1LL << bit);
}
}
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen ("task.inp", "r")) {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
}
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) {
cin >> s[i]; s[i] += s[i - 1];
}
if (a == 1) sub5();
else sub4();
cout << res;
}
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... |