Submission #489694

#TimeUsernameProblemLanguageResultExecution timeMemory
489694mdn2002Bali Sculptures (APIO15_sculpture)C++14
9 / 100
1096 ms31820 KiB
//#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 ) ); } return dp [x][num] = ans; } void ff ( int x , int num , long long sum , long long tmp ) { 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...