# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
270487 | BeanZ | Bali Sculptures (APIO15_sculpture) | C++14 | 494 ms | 1280 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
#define endl '\n'
const int N = 3e6 + 5;
ll dp[2005][2005], f[2005][2005], a[2005], sum[2005], d[2005], fp[2005];
ll ans = 0;
bool chk(ll now, ll s){
for (int i = 41; i >= s; i--){
if ((ans & (1ll << i)) == 0){
if (now & (1ll << i)){
return false;
}
}
}
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("VietCT.INP", "r")){
freopen("VietCT.INP", "r", stdin);
freopen("VietCT.OUT", "w", stdout);
}
ll n, L, R;
cin >> n >> L >> R;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
if (n > 100){
for (int s = 41; s >= 0; s--){
for (int i = 1; i <= n; i++){
fp[i] = d[i];
}
for (int i = 1; i <= n; i++){
if (fp[i] == -1) continue;
fp[i] = 1e9;
for (int j = 0; j < i; j++){
if (fp[j] == -1) continue;
ll cost = sum[i] - sum[j];
if (chk(cost, s)){
fp[i] = min(fp[i], fp[j] + 1);
}
}
if (fp[i] == 1e9) fp[i] = -1;
//cout << f[i] << " ";
}
//cout << endl;
if (fp[n] <= R && fp[n] != -1){
for (int i = 1; i <= n; i++){
if (fp[i] <= R) d[i] = fp[i];
else d[i] = -1;
}
} else {
ans = ans + (1ll << s);
}
}
cout << ans;
} else {
for (int i = 1; i <= R; i++){
for (int j = i; j <= n; j++){
dp[i][j] = 1;
}
}
for (int s = 41; s >= 0; s--){
for (int i = 1; i <= R; i++){
for (int j = i; j <= n; j++){
f[i][j] = dp[i][j];
//cout << f[i][j] << " " << i << " " << j << endl;
}
}
//cout << endl << endl;
for (int i = 1; i <= n; i++){
if (f[1][i] == 0) continue;
if (sum[i] & (1ll << s)) f[1][i] = 0;
//cout << f[1][i] << " " << 1 << " " << i << endl;
}
bool ok = false;
if (f[1][n] && 1 >= L) ok = true;
for (int i = 2; i <= R; i++){
for (int j = i; j <= n; j++){
if (f[i][j] == 0) continue;
bool flag = false;
for (int k = i - 1; k < j; k++){
if (f[i - 1][k] == 0) continue;
ll cost = sum[j] - sum[k];
if (chk(cost, s)){
flag = true;
break;
}
}
if (flag) f[i][j] = 1;
else f[i][j] = 0;
//cout << f[i][j] << " " << i << " " << j << endl;
}
if (i >= L && f[i][n]) ok = true;
}
//cout << ok << endl;
if (ok){
for (int i = 1; i <= R; i++){
for (int j = i; j <= n; j++){
dp[i][j] = f[i][j];
}
}
} else {
ans = ans + (1ll << s);
}
//cout << endl << endl;
}
cout << ans;
}
}
/*
6 1 3
8 1 2 1 5 4
*/
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... |