Submission #151690

# Submission time Handle Problem Language Result Execution time Memory
151690 2019-09-04T07:42:56 Z Ruxandra985 Bali Sculptures (APIO15_sculpture) C++14
0 / 100
2 ms 504 KB
/// aliens pe subtaskuri suna... mInUnAt
#include <cstdio>
#include <iostream>
#define DIMN 2010
#define INF 4000000000000
using namespace std;
int v[DIMN],cnt[DIMN],n;
long long dp[DIMN],sp[DIMN];
int check (int lambda , long long &sol){ /// sol = dp[n] , return = cnt[n]
    int i,poz,j;
    long long mini;
    for (i=1;i<=n;i++){
        mini = INF;
        poz = 0;
        for (j=i-1;j>=0;j--){
            if (mini > (dp[j] | (sp[i] - sp[j])) + lambda*(cnt[j] + 1)){
                mini = (dp[j] | (sp[i] - sp[j])) + lambda*(cnt[j] + 1);
                poz = j;
            }
        }
        dp[i] = (dp[poz] | (sp[i] - sp[poz]));
        cnt[i] = cnt[poz] + 1;
    }
    sol = dp[n];
    return cnt[n];
}
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int a,b,i,x,st,dr,mid;
    long long sol , 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;
        for (x=a;x<=b;x++){ /// aliens pe FIX x intervale
            st = 0;
            dr = 1000000000;
            while (st<=dr){
                mid = (st + dr)/2;
                sol = 0;
                if (check(mid,sol) > x)
                    st = mid + 1;
                else dr = mid - 1;
            }
            sol = 0;
            check (st-1,sol);
            if (x == a)
                solfinal = sol - (long long)x * (st-1);
            else solfinal = min (solfinal , sol - x * (st-1));
        }
    }
    else { /// a = 1 , b e idk , deci poti sa selectezi CEL MULT b intervale
        solfinal = 0;
        st = 0;
        dr = 1000000000;
        while (st<=dr){
            mid = (st + dr)/2;
            sol = 0;
            if (check(mid,sol) > b)
                st = mid + 1;
            else dr = mid - 1;
        }
        sol = 0;
        x = check (st-1,sol);
        solfinal = sol - (long long)x * (st-1);
    }
    fprintf (fout,"%lld",solfinal);
    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:33: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:35: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 time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -