답안 #151711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151711 2019-09-04T09:31:49 Z Ruxandra985 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
93 ms 832 KB
/// 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

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]);
         ~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 252 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 252 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 256 KB Output is correct
30 Correct 3 ms 256 KB Output is correct
31 Correct 3 ms 380 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 292 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 2 ms 256 KB Output is correct
38 Correct 2 ms 252 KB Output is correct
39 Correct 2 ms 256 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 256 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 364 KB Output is correct
46 Correct 2 ms 256 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 252 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 380 KB Output is correct
52 Correct 3 ms 376 KB Output is correct
53 Correct 3 ms 376 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 3 ms 376 KB Output is correct
56 Correct 2 ms 504 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 296 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 3 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 25 ms 760 KB Output is correct
65 Correct 5 ms 504 KB Output is correct
66 Correct 8 ms 632 KB Output is correct
67 Correct 11 ms 632 KB Output is correct
68 Correct 16 ms 760 KB Output is correct
69 Correct 20 ms 760 KB Output is correct
70 Correct 20 ms 760 KB Output is correct
71 Correct 21 ms 832 KB Output is correct
72 Correct 21 ms 760 KB Output is correct
73 Correct 21 ms 760 KB Output is correct
74 Correct 22 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 1 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 252 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 252 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 3 ms 420 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 256 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 256 KB Output is correct
44 Correct 2 ms 256 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 256 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 256 KB Output is correct
52 Correct 10 ms 376 KB Output is correct
53 Correct 16 ms 376 KB Output is correct
54 Correct 28 ms 376 KB Output is correct
55 Correct 26 ms 384 KB Output is correct
56 Correct 90 ms 376 KB Output is correct
57 Correct 89 ms 376 KB Output is correct
58 Correct 83 ms 248 KB Output is correct
59 Correct 86 ms 504 KB Output is correct
60 Correct 91 ms 376 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 16 ms 376 KB Output is correct
63 Correct 28 ms 504 KB Output is correct
64 Correct 26 ms 376 KB Output is correct
65 Correct 46 ms 388 KB Output is correct
66 Correct 67 ms 376 KB Output is correct
67 Correct 89 ms 376 KB Output is correct
68 Correct 93 ms 504 KB Output is correct
69 Correct 86 ms 376 KB Output is correct