# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
207639 | DystoriaX | Bali Sculptures (APIO15_sculpture) | C++14 | 211 ms | 504 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;
int n, a, b;
int y[100010];
bool dp[1010][1010];
int dp2[2010];
long long pref[1010], mx;
const int lgmx = 37;
long long lsb(long long x){
return x & (-x);
}
bool check(){
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
dp[i][j] = false;
dp[0][0] = true;
for(int j = 1; j <= n; j++){
for(int i = j; i <= n; i++){
for(int k = j - 1; k < i; k++){
long long sum = pref[i] - pref[k];
if(lsb(mx & sum) != lsb(mx) && (sum & (~mx)) <= lsb(mx)){
dp[i][j] |= dp[k][j - 1];
}
}
}
}
bool ret = false;
for(int i = a; i <= b; i++){
ret |= dp[n][i];
}
return ret;
}
void solve1(){
for(int i = lgmx; i >= 0; i--){
long long tmp = mx;
mx |= (1LL << i);
if(check()) mx = tmp;
}
printf("%lld\n", mx);
}
bool check2(){
for(int i = 0; i <= 2000; i++) dp2[i] = 1e9;
dp2[0] = 0;
for(int i = 0; i <= n; i++){
for(int k = i + 1; k <= n; k++){
long long sum = pref[k] - pref[i];
if(lsb(mx & sum) != lsb(mx) && (sum & (~mx)) <= lsb(mx)){
dp2[k] = min(dp2[k], dp2[i] + 1);
}
}
}
return dp2[n] <= b;
}
void solve2(){
for(int i = lgmx; i >= 0; i--){
long long tmp = mx;
mx |= (1LL << i);
if(check2()) mx = tmp;
}
printf("%lld\n", mx);
}
int main(){
// freopen("input.txt", "r", stdin);
scanf("%d%d%d", &n, &a, &b);
for(int i = 1; i <= n; i++){
scanf("%d", &y[i]);
pref[i] = y[i] + pref[i - 1];
}
if(n <= 100) solve1();
else 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... |