# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163373 | combi1k1 | Bali Sculptures (APIO15_sculpture) | C++14 | 4 ms | 632 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>
using namespace std;
#define ll long long
const int N = 2e3 + 1;
ll a[N];
ll f[N][N];
int g[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int A; cin >> A;
int B; cin >> B;
for(int i = 1 ; i <= n ; ++i) {
cin >> a[i];
a[i] += a[i - 1];
}
assert(A > 1);
if (A > 1) {
for(int i = 1 ; i <= n ; ++i)
f[i][0] = 1e18;
for(int i = 1 ; i <= n ; ++i)
for(int j = 1 ; j <= i ; ++j) {
f[i][j] = 1e18;
for(int k = j - 1 ; k < i ; ++k)
f[i][j] = min(f[i][j],f[k][j - 1] | (a[i] - a[k]));
}
ll ans = 1e18;
for(int i = A ; i <= B ; ++i)
ans = min(ans,f[n][i]);
cout << ans;
}
else {
ll cur_mask = 0;
for(int b = 40 ; b >= 0 ; --b) {
for(int i = 1 ; i <= n ; ++i) {
g[i] = 1e9;
int t = 0;
for(int j = 0 ; j < i ; ++j) {
ll S = a[i] - a[j];
S >>= b;
S <<= b;
if ((S & cur_mask) != S)
continue;
g[i] = min(g[i],g[j] + 1);
}
}
if (g[n] > B) cur_mask |= (1ll << b);
}
cout << cur_mask << endl;
}
}
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... |