#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 ( 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: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 |
94 ms |
15948 KB |
Output is correct |
2 |
Correct |
99 ms |
15980 KB |
Output is correct |
3 |
Correct |
94 ms |
15948 KB |
Output is correct |
4 |
Correct |
94 ms |
15984 KB |
Output is correct |
5 |
Correct |
93 ms |
15984 KB |
Output is correct |
6 |
Correct |
102 ms |
15984 KB |
Output is correct |
7 |
Correct |
97 ms |
15980 KB |
Output is correct |
8 |
Correct |
91 ms |
15996 KB |
Output is correct |
9 |
Correct |
92 ms |
15980 KB |
Output is correct |
10 |
Correct |
98 ms |
15980 KB |
Output is correct |
11 |
Correct |
98 ms |
15948 KB |
Output is correct |
12 |
Correct |
92 ms |
15948 KB |
Output is correct |
13 |
Correct |
96 ms |
15980 KB |
Output is correct |
14 |
Correct |
93 ms |
15976 KB |
Output is correct |
15 |
Correct |
94 ms |
15980 KB |
Output is correct |
16 |
Correct |
102 ms |
15972 KB |
Output is correct |
17 |
Correct |
96 ms |
15984 KB |
Output is correct |
18 |
Correct |
94 ms |
15980 KB |
Output is correct |
19 |
Correct |
94 ms |
15948 KB |
Output is correct |
20 |
Correct |
93 ms |
15976 KB |
Output is correct |
21 |
Correct |
97 ms |
15984 KB |
Output is correct |
22 |
Correct |
94 ms |
15976 KB |
Output is correct |
23 |
Correct |
93 ms |
15976 KB |
Output is correct |
24 |
Correct |
97 ms |
15992 KB |
Output is correct |
25 |
Correct |
96 ms |
15980 KB |
Output is correct |
26 |
Correct |
93 ms |
15980 KB |
Output is correct |
27 |
Incorrect |
92 ms |
15948 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15948 KB |
Output is correct |
2 |
Correct |
94 ms |
15996 KB |
Output is correct |
3 |
Correct |
94 ms |
15980 KB |
Output is correct |
4 |
Correct |
93 ms |
15980 KB |
Output is correct |
5 |
Correct |
92 ms |
15948 KB |
Output is correct |
6 |
Correct |
93 ms |
15984 KB |
Output is correct |
7 |
Correct |
96 ms |
15948 KB |
Output is correct |
8 |
Correct |
94 ms |
15988 KB |
Output is correct |
9 |
Correct |
97 ms |
15984 KB |
Output is correct |
10 |
Correct |
93 ms |
15948 KB |
Output is correct |
11 |
Correct |
93 ms |
15948 KB |
Output is correct |
12 |
Correct |
93 ms |
15992 KB |
Output is correct |
13 |
Correct |
97 ms |
15948 KB |
Output is correct |
14 |
Correct |
94 ms |
15948 KB |
Output is correct |
15 |
Correct |
95 ms |
15996 KB |
Output is correct |
16 |
Correct |
95 ms |
15948 KB |
Output is correct |
17 |
Correct |
93 ms |
15980 KB |
Output is correct |
18 |
Correct |
92 ms |
15948 KB |
Output is correct |
19 |
Correct |
94 ms |
15948 KB |
Output is correct |
20 |
Correct |
96 ms |
15992 KB |
Output is correct |
21 |
Correct |
94 ms |
15980 KB |
Output is correct |
22 |
Correct |
93 ms |
15888 KB |
Output is correct |
23 |
Correct |
92 ms |
15980 KB |
Output is correct |
24 |
Correct |
93 ms |
15984 KB |
Output is correct |
25 |
Correct |
99 ms |
15988 KB |
Output is correct |
26 |
Correct |
107 ms |
15948 KB |
Output is correct |
27 |
Correct |
93 ms |
15948 KB |
Output is correct |
28 |
Correct |
94 ms |
15948 KB |
Output is correct |
29 |
Correct |
93 ms |
15948 KB |
Output is correct |
30 |
Correct |
99 ms |
15948 KB |
Output is correct |
31 |
Correct |
94 ms |
15884 KB |
Output is correct |
32 |
Correct |
95 ms |
15988 KB |
Output is correct |
33 |
Correct |
103 ms |
15948 KB |
Output is correct |
34 |
Correct |
92 ms |
15984 KB |
Output is correct |
35 |
Correct |
92 ms |
15980 KB |
Output is correct |
36 |
Correct |
96 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15984 KB |
Output is correct |
2 |
Correct |
98 ms |
15988 KB |
Output is correct |
3 |
Correct |
94 ms |
15948 KB |
Output is correct |
4 |
Correct |
93 ms |
15948 KB |
Output is correct |
5 |
Correct |
96 ms |
16024 KB |
Output is correct |
6 |
Correct |
93 ms |
15948 KB |
Output is correct |
7 |
Correct |
97 ms |
15980 KB |
Output is correct |
8 |
Correct |
98 ms |
15992 KB |
Output is correct |
9 |
Correct |
91 ms |
15948 KB |
Output is correct |
10 |
Correct |
96 ms |
15988 KB |
Output is correct |
11 |
Correct |
94 ms |
15984 KB |
Output is correct |
12 |
Correct |
94 ms |
15984 KB |
Output is correct |
13 |
Correct |
93 ms |
15948 KB |
Output is correct |
14 |
Correct |
92 ms |
15948 KB |
Output is correct |
15 |
Correct |
97 ms |
15984 KB |
Output is correct |
16 |
Correct |
92 ms |
15984 KB |
Output is correct |
17 |
Correct |
93 ms |
15948 KB |
Output is correct |
18 |
Correct |
94 ms |
15948 KB |
Output is correct |
19 |
Correct |
92 ms |
15948 KB |
Output is correct |
20 |
Correct |
98 ms |
16000 KB |
Output is correct |
21 |
Correct |
93 ms |
15948 KB |
Output is correct |
22 |
Correct |
93 ms |
16072 KB |
Output is correct |
23 |
Correct |
96 ms |
15980 KB |
Output is correct |
24 |
Correct |
93 ms |
15988 KB |
Output is correct |
25 |
Correct |
98 ms |
15980 KB |
Output is correct |
26 |
Correct |
94 ms |
16068 KB |
Output is correct |
27 |
Correct |
94 ms |
15988 KB |
Output is correct |
28 |
Correct |
93 ms |
15948 KB |
Output is correct |
29 |
Correct |
95 ms |
15988 KB |
Output is correct |
30 |
Correct |
94 ms |
15984 KB |
Output is correct |
31 |
Correct |
95 ms |
15988 KB |
Output is correct |
32 |
Correct |
95 ms |
15948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
15984 KB |
Output is correct |
2 |
Correct |
96 ms |
15988 KB |
Output is correct |
3 |
Correct |
93 ms |
15984 KB |
Output is correct |
4 |
Correct |
95 ms |
15980 KB |
Output is correct |
5 |
Correct |
93 ms |
15948 KB |
Output is correct |
6 |
Correct |
91 ms |
15984 KB |
Output is correct |
7 |
Correct |
94 ms |
15988 KB |
Output is correct |
8 |
Correct |
98 ms |
15948 KB |
Output is correct |
9 |
Correct |
92 ms |
15948 KB |
Output is correct |
10 |
Correct |
98 ms |
15948 KB |
Output is correct |
11 |
Correct |
93 ms |
15948 KB |
Output is correct |
12 |
Correct |
91 ms |
15980 KB |
Output is correct |
13 |
Correct |
103 ms |
15980 KB |
Output is correct |
14 |
Correct |
95 ms |
15976 KB |
Output is correct |
15 |
Correct |
99 ms |
15948 KB |
Output is correct |
16 |
Correct |
91 ms |
15948 KB |
Output is correct |
17 |
Correct |
94 ms |
15980 KB |
Output is correct |
18 |
Correct |
94 ms |
15948 KB |
Output is correct |
19 |
Correct |
96 ms |
15948 KB |
Output is correct |
20 |
Correct |
105 ms |
15980 KB |
Output is correct |
21 |
Correct |
95 ms |
15976 KB |
Output is correct |
22 |
Correct |
98 ms |
15948 KB |
Output is correct |
23 |
Correct |
93 ms |
15948 KB |
Output is correct |
24 |
Correct |
91 ms |
15980 KB |
Output is correct |
25 |
Correct |
96 ms |
15976 KB |
Output is correct |
26 |
Correct |
96 ms |
15948 KB |
Output is correct |
27 |
Incorrect |
95 ms |
15976 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
15980 KB |
Output is correct |
2 |
Correct |
95 ms |
15980 KB |
Output is correct |
3 |
Correct |
98 ms |
15980 KB |
Output is correct |
4 |
Correct |
94 ms |
15948 KB |
Output is correct |
5 |
Correct |
93 ms |
15984 KB |
Output is correct |
6 |
Correct |
94 ms |
15984 KB |
Output is correct |
7 |
Correct |
95 ms |
15988 KB |
Output is correct |
8 |
Correct |
99 ms |
15980 KB |
Output is correct |
9 |
Correct |
96 ms |
15984 KB |
Output is correct |
10 |
Correct |
93 ms |
15948 KB |
Output is correct |
11 |
Correct |
96 ms |
15948 KB |
Output is correct |
12 |
Correct |
92 ms |
15948 KB |
Output is correct |
13 |
Correct |
95 ms |
15940 KB |
Output is correct |
14 |
Incorrect |
96 ms |
15984 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |