# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151711 | Ruxandra985 | Bali Sculptures (APIO15_sculpture) | C++14 | 93 ms | 832 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.
/// ups nu e aliens:)))
/// ok aparent bv rux dar nu merge dinamica clasica daca ai or:))))
/// ar trebui sa mearga pe toate?:)
#include <cstdio>
#include <iostream>
#define DIMN 2010
#define INF 4000000000000
using namespace std;
int v[DIMN],cnt[DIMN],n;
int dp[DIMN][DIMN];
long long sp[DIMN];
int check (long long target , int a , int b){
int i,j;
/// daca ai 0 in target , nu poti sa pui tu 1
dp[0][0] = 1;
for (i=1;i<=n;i++){
for (j=1;j<=i;j++){
dp[i][j] = 0;
for (int k=i-1;k>=0;k--){
if( (target | (sp[i] - sp[k])) <= target ){
dp[i][j] = (dp[i][j] | dp[k][j-1]);
}
}
}
}
for (j=a;j<=b;j++){
if (dp[n][j])
return 0;
}
return 1;
}
int check2 (long long target){
int i,j;
/// daca ai 0 in target , nu poti sa pui tu 1
for (i=1;i<=n;i++){
cnt[i] = n + 1;
for (j=i-1;j>=0;j--){
if ((target | (sp[i] - sp[j])) <= target){ /// respecta
cnt[i] = min (cnt[i] , cnt[j] + 1);
}
}
}
return cnt[n];
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int a,b,i,x;
long long solfinal;
fscanf (fin,"%d%d%d",&n,&a,&b);
for (i=1;i<=n;i++){
fscanf (fin,"%d",&v[i]);
sp[i] = sp[i-1] + v[i];
}
if (a!=1){
solfinal = 0; /// prefix
long long bit = ((long long)1<<40);
for (;bit;bit/=2){
if (check(solfinal + bit-1,a,b)){ /// prefixul stabilit , bit e 0, restul 1
solfinal = solfinal + bit; /// nu se poate sa ai 0 pe poz bit
}
}
}
else { /// a = 1 , b e idk , deci poti sa selectezi CEL MULT b intervale
solfinal = 0; /// prefix
long long bit = ((long long)1<<40);
for (;bit;bit/=2){
if (check2(solfinal + bit-1) > b){ /// prefixul stabilit , bit e 0, restul 1
solfinal = solfinal + bit; /// nu se poate sa ai 0 pe poz bit
}
}
}
fprintf (fout,"%lld",solfinal);
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... |