//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
long long n , a , b , y [2003] , dp [2003][2003] , ans = 1e16;
long long f ( int x , int num )
{
if ( x == n && a <= num && num <= b ) return 0;
if ( x == n ) return 1e16;
//if ( dp [x][num] != -1 ) return dp [x][num];
long long ans = 1e16 , sum = 0;
for ( int i = x ; i < n ; i ++ )
{
sum += y [i];
ans = min ( ans , ( f ( i + 1 , num + 1 ) | sum ) );
}
if ( x == 0 ) cout << f ( 1 , 1 ) << endl;
return dp [x][num] = ans;
}
void ff ( int x , int num , long long sum , long long tmp )
{
if ( num > b ) return;
if ( x == n && a <= num && num <= b )
{
ans = min ( ans , ( tmp | sum ) );
return;
}
if ( x == n ) return;
ff ( x + 1 , num + 1 , 0 , ( tmp | ( sum + y [x] ) ) );
if ( x + 1 != n ) ff ( x + 1 , num , sum + y [x] , tmp );
}
int main()
{
//freopen ( "fence8.in" , "r" , stdin );
//freopen ( "fence8.out" , "w" , stdout );
memset ( dp , -1 , sizeof dp );
cin >> n >> a >> b;
for ( int i = 0 ; i < n ; i ++ ) cin >> y [i];
ff ( 0 , 0 , 0 , 0 );
cout << ans << endl;
cout << f ( 0 , 0 );
}
/*
4 1 4
8 3 4 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
31692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
31692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
31596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
31632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
31640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |