Submission #489716

# Submission time Handle Problem Language Result Execution time Memory
489716 2021-11-24T03:21:58 Z mdn2002 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
331 ms 31820 KB
#include<bits/stdc++.h>
using namespace std;
long long n , a , b , y [2003] , dp [2003][2003] , dpp [2003] , pre [2003];
long long mask;
bool f ( int x , int num )
{
    if ( x == n + 1 )
    {
        if ( a <= num && num <= b ) return 1;
        return 0;
    }
    if ( dp [x][num] != -1 ) return dp [x][num];
    bool ans = 0;
    long long sum = 0;
    for ( int i = x ; i <= n ; i ++ )
    {
        sum += y [i];
        if ( ( mask | sum ) > mask ) continue;
        ans = max ( ans , f ( i + 1 , num + 1 ) );
    }
    return dp [x][num] = ans;
}
long long ff ( )
{
    for ( int i = 1 ; i <= n ; i ++ ) dpp [i] = 1e8;
    for ( int i = 1 ; i <= n ; i ++ )
    {
        for ( int j = 1 ; j <= i ; j ++ )
        {
            long long sum = pre [i] - pre [ j - 1 ];
            if ( ( mask | sum ) > mask ) continue;
            dpp [i] = min ( dpp [i] , dpp [ j - 1 ] + 1 );
        }
    }
    return dpp [n];
}
bool ck ( )
{
    memset ( dp , -1 , sizeof dp );
    if ( a != 1 ) return f ( 1 , 0 );
    else
    {
        int mn = ff ( );
        return ( mn <= b );
    }
}
int main()
{
    //freopen ( "fence8.in" , "r" , stdin );
    //freopen ( "fence8.out" , "w" , stdout );
    scanf ( "%d%d%d" , &n , &a , &b );
    for ( int i = 1 ; i <= n ; i ++ )
    {
        scanf ( "%d" , &y [i] );
        pre [i] = y [i] + pre [ i - 1 ];
    }
    mask = ( 1ll << 50 ) - 1;
    for ( int i = 49 ; i >= 0 ; i -- )
    {
        mask ^= ( 1ll << i );
        if ( ck ( ) == 0 ) mask ^= ( 1ll << i );
    }
    printf ( "%lld" , mask );
}

Compilation message

sculpture.cpp: In function 'bool f(int, int)':
sculpture.cpp:21:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   21 |     return dp [x][num] = ans;
      |            ~~~~~~~~~~~~^~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:51:15: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   51 |     scanf ( "%d%d%d" , &n , &a , &b );
      |              ~^        ~~
      |               |        |
      |               int*     long long int*
      |              %lld
sculpture.cpp:51:17: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   51 |     scanf ( "%d%d%d" , &n , &a , &b );
      |                ~^           ~~
      |                 |           |
      |                 int*        long long int*
      |                %lld
sculpture.cpp:51:19: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
   51 |     scanf ( "%d%d%d" , &n , &a , &b );
      |                  ~^              ~~
      |                   |              |
      |                   int*           long long int*
      |                  %lld
sculpture.cpp:54:19: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   54 |         scanf ( "%d" , &y [i] );
      |                  ~^    ~~~~~~
      |                   |    |
      |                   int* long long int*
      |                  %lld
sculpture.cpp:51:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf ( "%d%d%d" , &n , &a , &b );
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:54:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf ( "%d" , &y [i] );
      |         ~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 199 ms 31600 KB Output is correct
2 Correct 187 ms 31704 KB Output is correct
3 Correct 195 ms 31692 KB Output is correct
4 Correct 186 ms 31696 KB Output is correct
5 Correct 201 ms 31692 KB Output is correct
6 Correct 189 ms 31692 KB Output is correct
7 Correct 192 ms 31812 KB Output is correct
8 Correct 187 ms 31692 KB Output is correct
9 Correct 184 ms 31684 KB Output is correct
10 Correct 191 ms 31692 KB Output is correct
11 Correct 193 ms 31692 KB Output is correct
12 Correct 185 ms 31692 KB Output is correct
13 Correct 193 ms 31688 KB Output is correct
14 Correct 185 ms 31696 KB Output is correct
15 Correct 195 ms 31692 KB Output is correct
16 Correct 184 ms 31692 KB Output is correct
17 Correct 197 ms 31692 KB Output is correct
18 Correct 189 ms 31692 KB Output is correct
19 Correct 183 ms 31680 KB Output is correct
20 Correct 193 ms 31680 KB Output is correct
21 Correct 186 ms 31700 KB Output is correct
22 Correct 192 ms 31692 KB Output is correct
23 Correct 185 ms 31692 KB Output is correct
24 Correct 195 ms 31692 KB Output is correct
25 Correct 186 ms 31692 KB Output is correct
26 Correct 188 ms 31684 KB Output is correct
27 Correct 188 ms 31692 KB Output is correct
28 Correct 187 ms 31692 KB Output is correct
29 Correct 202 ms 31692 KB Output is correct
30 Correct 188 ms 31692 KB Output is correct
31 Correct 193 ms 31692 KB Output is correct
32 Correct 196 ms 31692 KB Output is correct
33 Correct 186 ms 31692 KB Output is correct
34 Correct 184 ms 31632 KB Output is correct
35 Correct 199 ms 31812 KB Output is correct
36 Correct 183 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 31692 KB Output is correct
2 Correct 188 ms 31692 KB Output is correct
3 Correct 186 ms 31692 KB Output is correct
4 Correct 194 ms 31692 KB Output is correct
5 Correct 182 ms 31688 KB Output is correct
6 Correct 185 ms 31688 KB Output is correct
7 Correct 188 ms 31692 KB Output is correct
8 Correct 190 ms 31684 KB Output is correct
9 Correct 194 ms 31692 KB Output is correct
10 Correct 191 ms 31636 KB Output is correct
11 Correct 185 ms 31684 KB Output is correct
12 Correct 190 ms 31692 KB Output is correct
13 Correct 188 ms 31692 KB Output is correct
14 Correct 181 ms 31588 KB Output is correct
15 Correct 215 ms 31692 KB Output is correct
16 Correct 206 ms 31692 KB Output is correct
17 Correct 184 ms 31764 KB Output is correct
18 Correct 182 ms 31692 KB Output is correct
19 Correct 183 ms 31692 KB Output is correct
20 Correct 186 ms 31692 KB Output is correct
21 Correct 203 ms 31692 KB Output is correct
22 Correct 183 ms 31692 KB Output is correct
23 Correct 194 ms 31684 KB Output is correct
24 Correct 184 ms 31700 KB Output is correct
25 Correct 183 ms 31692 KB Output is correct
26 Correct 183 ms 31688 KB Output is correct
27 Correct 186 ms 31692 KB Output is correct
28 Correct 183 ms 31692 KB Output is correct
29 Correct 185 ms 31692 KB Output is correct
30 Correct 189 ms 31684 KB Output is correct
31 Correct 199 ms 31688 KB Output is correct
32 Correct 202 ms 31692 KB Output is correct
33 Correct 202 ms 31692 KB Output is correct
34 Correct 189 ms 31692 KB Output is correct
35 Correct 184 ms 31692 KB Output is correct
36 Correct 183 ms 31680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 31812 KB Output is correct
2 Correct 185 ms 31664 KB Output is correct
3 Correct 184 ms 31684 KB Output is correct
4 Correct 184 ms 31692 KB Output is correct
5 Correct 195 ms 31692 KB Output is correct
6 Correct 184 ms 31692 KB Output is correct
7 Correct 189 ms 31692 KB Output is correct
8 Correct 188 ms 31684 KB Output is correct
9 Correct 185 ms 31812 KB Output is correct
10 Correct 202 ms 31684 KB Output is correct
11 Correct 192 ms 31692 KB Output is correct
12 Correct 186 ms 31692 KB Output is correct
13 Correct 188 ms 31688 KB Output is correct
14 Correct 186 ms 31684 KB Output is correct
15 Correct 187 ms 31692 KB Output is correct
16 Correct 197 ms 31692 KB Output is correct
17 Correct 197 ms 31692 KB Output is correct
18 Correct 191 ms 31696 KB Output is correct
19 Correct 190 ms 31812 KB Output is correct
20 Correct 197 ms 31692 KB Output is correct
21 Correct 183 ms 31668 KB Output is correct
22 Correct 194 ms 31740 KB Output is correct
23 Correct 195 ms 31688 KB Output is correct
24 Correct 197 ms 31688 KB Output is correct
25 Correct 189 ms 31692 KB Output is correct
26 Correct 184 ms 31692 KB Output is correct
27 Correct 185 ms 31692 KB Output is correct
28 Correct 185 ms 31692 KB Output is correct
29 Correct 190 ms 31696 KB Output is correct
30 Correct 188 ms 31692 KB Output is correct
31 Correct 185 ms 31692 KB Output is correct
32 Correct 189 ms 31692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 31684 KB Output is correct
2 Correct 184 ms 31692 KB Output is correct
3 Correct 199 ms 31688 KB Output is correct
4 Correct 187 ms 31692 KB Output is correct
5 Correct 185 ms 31692 KB Output is correct
6 Correct 193 ms 31692 KB Output is correct
7 Correct 196 ms 31692 KB Output is correct
8 Correct 188 ms 31712 KB Output is correct
9 Correct 186 ms 31692 KB Output is correct
10 Correct 187 ms 31692 KB Output is correct
11 Correct 188 ms 31692 KB Output is correct
12 Correct 183 ms 31812 KB Output is correct
13 Correct 185 ms 31692 KB Output is correct
14 Correct 184 ms 31608 KB Output is correct
15 Correct 185 ms 31692 KB Output is correct
16 Correct 185 ms 31684 KB Output is correct
17 Correct 186 ms 31692 KB Output is correct
18 Correct 188 ms 31680 KB Output is correct
19 Correct 185 ms 31692 KB Output is correct
20 Correct 185 ms 31692 KB Output is correct
21 Correct 186 ms 31696 KB Output is correct
22 Correct 186 ms 31692 KB Output is correct
23 Correct 186 ms 31704 KB Output is correct
24 Correct 183 ms 31692 KB Output is correct
25 Correct 192 ms 31696 KB Output is correct
26 Correct 188 ms 31684 KB Output is correct
27 Correct 184 ms 31692 KB Output is correct
28 Correct 197 ms 31576 KB Output is correct
29 Correct 186 ms 31692 KB Output is correct
30 Correct 189 ms 31688 KB Output is correct
31 Correct 188 ms 31700 KB Output is correct
32 Correct 187 ms 31656 KB Output is correct
33 Correct 188 ms 31692 KB Output is correct
34 Correct 183 ms 31692 KB Output is correct
35 Correct 190 ms 31692 KB Output is correct
36 Correct 183 ms 31688 KB Output is correct
37 Correct 184 ms 31692 KB Output is correct
38 Correct 190 ms 31692 KB Output is correct
39 Correct 188 ms 31692 KB Output is correct
40 Correct 187 ms 31692 KB Output is correct
41 Correct 193 ms 31672 KB Output is correct
42 Correct 184 ms 31704 KB Output is correct
43 Correct 186 ms 31692 KB Output is correct
44 Correct 187 ms 31692 KB Output is correct
45 Correct 187 ms 31684 KB Output is correct
46 Correct 186 ms 31692 KB Output is correct
47 Correct 189 ms 31692 KB Output is correct
48 Correct 205 ms 31696 KB Output is correct
49 Correct 187 ms 31692 KB Output is correct
50 Correct 186 ms 31692 KB Output is correct
51 Correct 184 ms 31640 KB Output is correct
52 Correct 187 ms 31656 KB Output is correct
53 Correct 184 ms 31692 KB Output is correct
54 Correct 185 ms 31692 KB Output is correct
55 Correct 199 ms 31680 KB Output is correct
56 Correct 187 ms 31692 KB Output is correct
57 Correct 187 ms 31692 KB Output is correct
58 Correct 184 ms 31692 KB Output is correct
59 Correct 186 ms 31692 KB Output is correct
60 Correct 186 ms 31688 KB Output is correct
61 Correct 190 ms 31688 KB Output is correct
62 Correct 186 ms 31692 KB Output is correct
63 Correct 190 ms 31692 KB Output is correct
64 Correct 210 ms 31692 KB Output is correct
65 Correct 189 ms 31692 KB Output is correct
66 Correct 196 ms 31696 KB Output is correct
67 Correct 195 ms 31692 KB Output is correct
68 Correct 193 ms 31628 KB Output is correct
69 Correct 201 ms 31812 KB Output is correct
70 Correct 207 ms 31696 KB Output is correct
71 Correct 205 ms 31688 KB Output is correct
72 Correct 209 ms 31692 KB Output is correct
73 Correct 204 ms 31688 KB Output is correct
74 Correct 199 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 31692 KB Output is correct
2 Correct 188 ms 31696 KB Output is correct
3 Correct 192 ms 31692 KB Output is correct
4 Correct 198 ms 31668 KB Output is correct
5 Correct 188 ms 31692 KB Output is correct
6 Correct 183 ms 31812 KB Output is correct
7 Correct 188 ms 31692 KB Output is correct
8 Correct 186 ms 31692 KB Output is correct
9 Correct 192 ms 31692 KB Output is correct
10 Correct 185 ms 31684 KB Output is correct
11 Correct 190 ms 31692 KB Output is correct
12 Correct 190 ms 31692 KB Output is correct
13 Correct 193 ms 31692 KB Output is correct
14 Correct 182 ms 31688 KB Output is correct
15 Correct 186 ms 31596 KB Output is correct
16 Correct 187 ms 31692 KB Output is correct
17 Correct 185 ms 31668 KB Output is correct
18 Correct 183 ms 31692 KB Output is correct
19 Correct 186 ms 31692 KB Output is correct
20 Correct 186 ms 31692 KB Output is correct
21 Correct 186 ms 31692 KB Output is correct
22 Correct 190 ms 31692 KB Output is correct
23 Correct 188 ms 31816 KB Output is correct
24 Correct 185 ms 31692 KB Output is correct
25 Correct 189 ms 31608 KB Output is correct
26 Correct 192 ms 31692 KB Output is correct
27 Correct 188 ms 31692 KB Output is correct
28 Correct 182 ms 31688 KB Output is correct
29 Correct 189 ms 31812 KB Output is correct
30 Correct 207 ms 31688 KB Output is correct
31 Correct 190 ms 31692 KB Output is correct
32 Correct 205 ms 31692 KB Output is correct
33 Correct 190 ms 31696 KB Output is correct
34 Correct 186 ms 31660 KB Output is correct
35 Correct 208 ms 31692 KB Output is correct
36 Correct 197 ms 31700 KB Output is correct
37 Correct 189 ms 31692 KB Output is correct
38 Correct 188 ms 31688 KB Output is correct
39 Correct 185 ms 31692 KB Output is correct
40 Correct 197 ms 31604 KB Output is correct
41 Correct 184 ms 31692 KB Output is correct
42 Correct 189 ms 31692 KB Output is correct
43 Correct 189 ms 31696 KB Output is correct
44 Correct 191 ms 31700 KB Output is correct
45 Correct 188 ms 31692 KB Output is correct
46 Correct 192 ms 31684 KB Output is correct
47 Correct 186 ms 31668 KB Output is correct
48 Correct 184 ms 31692 KB Output is correct
49 Correct 194 ms 31692 KB Output is correct
50 Correct 190 ms 31700 KB Output is correct
51 Correct 197 ms 31692 KB Output is correct
52 Correct 201 ms 31692 KB Output is correct
53 Correct 205 ms 31708 KB Output is correct
54 Correct 225 ms 31724 KB Output is correct
55 Correct 222 ms 31692 KB Output is correct
56 Correct 310 ms 31820 KB Output is correct
57 Correct 317 ms 31744 KB Output is correct
58 Correct 311 ms 31740 KB Output is correct
59 Correct 320 ms 31692 KB Output is correct
60 Correct 329 ms 31748 KB Output is correct
61 Correct 187 ms 31692 KB Output is correct
62 Correct 208 ms 31712 KB Output is correct
63 Correct 224 ms 31692 KB Output is correct
64 Correct 217 ms 31728 KB Output is correct
65 Correct 256 ms 31740 KB Output is correct
66 Correct 287 ms 31748 KB Output is correct
67 Correct 331 ms 31760 KB Output is correct
68 Correct 312 ms 31744 KB Output is correct
69 Correct 313 ms 31692 KB Output is correct