답안 #489714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489714 2021-11-24T03:19:55 Z mdn2002 Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 16076 KB
#include<bits/stdc++.h>
using namespace std;
int 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 ( n != 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: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] );
      |         ~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 15948 KB Output is correct
2 Correct 94 ms 15980 KB Output is correct
3 Correct 98 ms 15988 KB Output is correct
4 Correct 94 ms 15980 KB Output is correct
5 Correct 97 ms 15980 KB Output is correct
6 Correct 94 ms 15980 KB Output is correct
7 Correct 95 ms 15948 KB Output is correct
8 Correct 100 ms 15980 KB Output is correct
9 Correct 93 ms 15984 KB Output is correct
10 Correct 93 ms 15948 KB Output is correct
11 Correct 93 ms 15976 KB Output is correct
12 Correct 95 ms 15980 KB Output is correct
13 Correct 94 ms 15980 KB Output is correct
14 Correct 95 ms 15948 KB Output is correct
15 Correct 95 ms 15948 KB Output is correct
16 Correct 96 ms 15976 KB Output is correct
17 Correct 94 ms 15976 KB Output is correct
18 Correct 101 ms 15980 KB Output is correct
19 Correct 96 ms 15976 KB Output is correct
20 Correct 101 ms 15980 KB Output is correct
21 Correct 95 ms 15948 KB Output is correct
22 Correct 98 ms 15940 KB Output is correct
23 Correct 95 ms 15948 KB Output is correct
24 Correct 103 ms 15976 KB Output is correct
25 Correct 96 ms 15976 KB Output is correct
26 Correct 100 ms 15948 KB Output is correct
27 Correct 93 ms 15980 KB Output is correct
28 Correct 94 ms 15980 KB Output is correct
29 Correct 96 ms 15992 KB Output is correct
30 Correct 94 ms 15948 KB Output is correct
31 Correct 93 ms 15984 KB Output is correct
32 Correct 98 ms 15980 KB Output is correct
33 Correct 94 ms 15948 KB Output is correct
34 Correct 97 ms 16068 KB Output is correct
35 Correct 94 ms 15980 KB Output is correct
36 Correct 100 ms 15984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 15984 KB Output is correct
2 Correct 96 ms 16068 KB Output is correct
3 Correct 97 ms 15984 KB Output is correct
4 Correct 94 ms 15980 KB Output is correct
5 Correct 94 ms 15976 KB Output is correct
6 Correct 94 ms 15976 KB Output is correct
7 Correct 97 ms 15980 KB Output is correct
8 Correct 94 ms 15948 KB Output is correct
9 Correct 100 ms 15980 KB Output is correct
10 Correct 102 ms 15984 KB Output is correct
11 Correct 94 ms 16068 KB Output is correct
12 Correct 93 ms 15980 KB Output is correct
13 Correct 99 ms 15980 KB Output is correct
14 Correct 93 ms 15948 KB Output is correct
15 Correct 96 ms 15948 KB Output is correct
16 Correct 95 ms 15960 KB Output is correct
17 Correct 93 ms 15948 KB Output is correct
18 Correct 95 ms 16068 KB Output is correct
19 Correct 99 ms 15948 KB Output is correct
20 Correct 92 ms 15948 KB Output is correct
21 Correct 95 ms 15984 KB Output is correct
22 Correct 92 ms 15980 KB Output is correct
23 Correct 97 ms 15948 KB Output is correct
24 Correct 92 ms 15948 KB Output is correct
25 Correct 93 ms 15980 KB Output is correct
26 Correct 93 ms 15948 KB Output is correct
27 Correct 92 ms 15948 KB Output is correct
28 Correct 94 ms 15980 KB Output is correct
29 Correct 101 ms 15980 KB Output is correct
30 Correct 96 ms 15948 KB Output is correct
31 Correct 97 ms 15948 KB Output is correct
32 Correct 106 ms 15948 KB Output is correct
33 Correct 97 ms 15948 KB Output is correct
34 Correct 108 ms 15992 KB Output is correct
35 Correct 101 ms 15948 KB Output is correct
36 Correct 97 ms 15948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 15948 KB Output is correct
2 Correct 96 ms 15980 KB Output is correct
3 Correct 94 ms 15984 KB Output is correct
4 Correct 96 ms 16076 KB Output is correct
5 Correct 94 ms 15976 KB Output is correct
6 Correct 95 ms 15976 KB Output is correct
7 Correct 94 ms 15980 KB Output is correct
8 Correct 94 ms 15880 KB Output is correct
9 Correct 95 ms 15980 KB Output is correct
10 Correct 97 ms 15980 KB Output is correct
11 Correct 95 ms 15948 KB Output is correct
12 Correct 92 ms 15976 KB Output is correct
13 Correct 94 ms 15996 KB Output is correct
14 Correct 96 ms 15976 KB Output is correct
15 Correct 94 ms 15928 KB Output is correct
16 Correct 94 ms 15948 KB Output is correct
17 Correct 104 ms 15948 KB Output is correct
18 Correct 98 ms 15984 KB Output is correct
19 Correct 101 ms 15988 KB Output is correct
20 Correct 100 ms 15980 KB Output is correct
21 Correct 97 ms 15948 KB Output is correct
22 Correct 97 ms 15984 KB Output is correct
23 Correct 96 ms 15892 KB Output is correct
24 Correct 102 ms 15948 KB Output is correct
25 Correct 116 ms 15976 KB Output is correct
26 Correct 123 ms 15980 KB Output is correct
27 Correct 117 ms 15980 KB Output is correct
28 Correct 129 ms 15980 KB Output is correct
29 Correct 129 ms 16048 KB Output is correct
30 Correct 125 ms 16076 KB Output is correct
31 Correct 126 ms 15972 KB Output is correct
32 Correct 126 ms 15988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 15992 KB Output is correct
2 Correct 97 ms 15976 KB Output is correct
3 Correct 91 ms 15948 KB Output is correct
4 Correct 93 ms 15948 KB Output is correct
5 Correct 103 ms 15980 KB Output is correct
6 Correct 94 ms 15948 KB Output is correct
7 Correct 91 ms 15976 KB Output is correct
8 Correct 92 ms 15948 KB Output is correct
9 Correct 91 ms 15980 KB Output is correct
10 Correct 105 ms 15948 KB Output is correct
11 Correct 93 ms 15980 KB Output is correct
12 Correct 94 ms 15948 KB Output is correct
13 Correct 92 ms 15948 KB Output is correct
14 Correct 95 ms 15984 KB Output is correct
15 Correct 93 ms 15948 KB Output is correct
16 Correct 100 ms 15948 KB Output is correct
17 Correct 97 ms 15992 KB Output is correct
18 Correct 96 ms 15976 KB Output is correct
19 Correct 97 ms 15948 KB Output is correct
20 Correct 94 ms 15948 KB Output is correct
21 Correct 96 ms 15948 KB Output is correct
22 Correct 95 ms 15984 KB Output is correct
23 Correct 92 ms 15976 KB Output is correct
24 Correct 93 ms 15976 KB Output is correct
25 Correct 94 ms 15948 KB Output is correct
26 Correct 94 ms 15976 KB Output is correct
27 Correct 91 ms 15984 KB Output is correct
28 Correct 93 ms 15948 KB Output is correct
29 Correct 93 ms 15976 KB Output is correct
30 Correct 95 ms 15984 KB Output is correct
31 Correct 93 ms 15948 KB Output is correct
32 Correct 92 ms 15980 KB Output is correct
33 Correct 91 ms 15976 KB Output is correct
34 Correct 98 ms 15980 KB Output is correct
35 Correct 93 ms 15976 KB Output is correct
36 Correct 91 ms 15948 KB Output is correct
37 Correct 92 ms 15984 KB Output is correct
38 Correct 95 ms 15984 KB Output is correct
39 Correct 104 ms 15980 KB Output is correct
40 Correct 94 ms 15980 KB Output is correct
41 Correct 98 ms 15980 KB Output is correct
42 Correct 104 ms 15972 KB Output is correct
43 Correct 98 ms 15948 KB Output is correct
44 Correct 102 ms 15980 KB Output is correct
45 Correct 96 ms 15948 KB Output is correct
46 Correct 97 ms 15948 KB Output is correct
47 Correct 100 ms 15908 KB Output is correct
48 Correct 101 ms 15984 KB Output is correct
49 Correct 110 ms 15980 KB Output is correct
50 Correct 116 ms 15948 KB Output is correct
51 Correct 124 ms 15948 KB Output is correct
52 Correct 124 ms 15948 KB Output is correct
53 Correct 127 ms 15980 KB Output is correct
54 Correct 129 ms 15980 KB Output is correct
55 Correct 124 ms 15984 KB Output is correct
56 Correct 95 ms 15984 KB Output is correct
57 Correct 99 ms 15980 KB Output is correct
58 Correct 102 ms 15948 KB Output is correct
59 Correct 115 ms 16068 KB Output is correct
60 Correct 107 ms 15980 KB Output is correct
61 Correct 106 ms 15948 KB Output is correct
62 Correct 111 ms 15988 KB Output is correct
63 Correct 110 ms 15948 KB Output is correct
64 Correct 122 ms 15948 KB Output is correct
65 Correct 94 ms 15976 KB Output is correct
66 Correct 99 ms 15948 KB Output is correct
67 Correct 99 ms 15984 KB Output is correct
68 Correct 103 ms 15948 KB Output is correct
69 Correct 117 ms 15984 KB Output is correct
70 Correct 105 ms 15948 KB Output is correct
71 Correct 107 ms 15948 KB Output is correct
72 Correct 108 ms 15948 KB Output is correct
73 Correct 108 ms 15980 KB Output is correct
74 Correct 110 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 15988 KB Output is correct
2 Correct 95 ms 15980 KB Output is correct
3 Correct 94 ms 15948 KB Output is correct
4 Correct 96 ms 15980 KB Output is correct
5 Correct 98 ms 16072 KB Output is correct
6 Correct 92 ms 15976 KB Output is correct
7 Correct 95 ms 15948 KB Output is correct
8 Correct 94 ms 15948 KB Output is correct
9 Correct 96 ms 15980 KB Output is correct
10 Correct 94 ms 15992 KB Output is correct
11 Correct 95 ms 15988 KB Output is correct
12 Correct 96 ms 15948 KB Output is correct
13 Correct 94 ms 15976 KB Output is correct
14 Correct 93 ms 15980 KB Output is correct
15 Correct 97 ms 15948 KB Output is correct
16 Correct 95 ms 15976 KB Output is correct
17 Correct 93 ms 15948 KB Output is correct
18 Correct 102 ms 15980 KB Output is correct
19 Correct 95 ms 15984 KB Output is correct
20 Correct 99 ms 15976 KB Output is correct
21 Correct 96 ms 15980 KB Output is correct
22 Correct 93 ms 15948 KB Output is correct
23 Correct 95 ms 15948 KB Output is correct
24 Correct 92 ms 15980 KB Output is correct
25 Correct 96 ms 15948 KB Output is correct
26 Correct 100 ms 15976 KB Output is correct
27 Correct 99 ms 15980 KB Output is correct
28 Correct 97 ms 15948 KB Output is correct
29 Correct 97 ms 15972 KB Output is correct
30 Correct 100 ms 15980 KB Output is correct
31 Correct 101 ms 15984 KB Output is correct
32 Correct 97 ms 15976 KB Output is correct
33 Correct 98 ms 15948 KB Output is correct
34 Correct 103 ms 15988 KB Output is correct
35 Correct 103 ms 15948 KB Output is correct
36 Correct 112 ms 15948 KB Output is correct
37 Correct 119 ms 15980 KB Output is correct
38 Correct 144 ms 15984 KB Output is correct
39 Correct 142 ms 15984 KB Output is correct
40 Correct 134 ms 15948 KB Output is correct
41 Correct 130 ms 15980 KB Output is correct
42 Correct 132 ms 15948 KB Output is correct
43 Correct 96 ms 15980 KB Output is correct
44 Correct 104 ms 15980 KB Output is correct
45 Correct 104 ms 15980 KB Output is correct
46 Correct 108 ms 15948 KB Output is correct
47 Correct 107 ms 15984 KB Output is correct
48 Correct 106 ms 15980 KB Output is correct
49 Correct 107 ms 15948 KB Output is correct
50 Correct 108 ms 15948 KB Output is correct
51 Correct 112 ms 15996 KB Output is correct
52 Execution timed out 1083 ms 16004 KB Time limit exceeded
53 Halted 0 ms 0 KB -