Submission #151711

#TimeUsernameProblemLanguageResultExecution timeMemory
151711Ruxandra985Bali Sculptures (APIO15_sculpture)C++14
100 / 100
93 ms832 KiB
/// 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)

sculpture.cpp: In function 'int main()':
sculpture.cpp:50:15: warning: unused variable 'x' [-Wunused-variable]
     int a,b,i,x;
               ^
sculpture.cpp:52:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d%d",&n,&a,&b);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:54:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d",&v[i]);
         ~~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...