Submission #489712

#TimeUsernameProblemLanguageResultExecution timeMemory
489712mdn2002Bali Sculptures (APIO15_sculpture)C++14
71 / 100
141 ms16108 KiB
#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] = 1e10; 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 <= 100 ) 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 (stderr)

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 'long long int ff()':
sculpture.cpp:25:49: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
   25 |     for ( int i = 1 ; i <= n ; i ++ ) dpp [i] = 1e10;
      |                                                 ^~~~
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] );
      |         ~~~~~~^~~~~~~~~~~~~~~~~
#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...