Submission #37162

#TimeUsernameProblemLanguageResultExecution timeMemory
37162chonkaBootfall (IZhO17_bootfall)C++98
100 / 100
476 ms7888 KiB
#include<iostream> #include<stdio.h> #include<vector> using namespace std ; #define MAXN 507 int n ; int a[ MAXN ] ; long long f[ MAXN * MAXN ] ; long long w[ MAXN * MAXN ] ; int ans[ MAXN * MAXN ] ; int sm ; void input ( ) { scanf ( "%d" , &n ) ; int i , j ; f[ 0 ] = 1 ; sm = 0 ; for ( i = 1 ; i <= n ; i ++ ) { scanf ( "%d" , &a[ i ] ) ; for ( j = sm ; j >= 0 ; j -- ) { f[ j + a[ i ] ] += f[ j ] ; } sm += a[ i ] ; } } void solve ( ) { int i , j ; if ( ( sm % 2 ) != 0 ) { printf ( "0\n" ) ; return ; } if ( f[ ( sm / 2 ) ] == 0 ) { printf ( "0\n" ) ; return ; } for ( i = 1 ; i <= n ; i ++ ) { for ( j = 0 ; j <= sm ; j ++ ) { w[ j ] = f[ j ] ; } for ( j = a[ i ] ; j <= sm ; j ++ ) { w[ j ] -= w[ j - a[ i ] ] ; } for ( j = 1 ; j <= sm ; j ++ ) { int p = ( sm + j - a[ i ] ) ; if ( ( p % 2 ) != 0 ) { continue ; } p /= 2 ; if ( w[ p ] != 0 ) { ans[ j ] ++ ; } } } vector < int > ret ; for ( i = 1 ; i <= sm ; i ++ ) { if ( ans[ i ] == n ) { ret.push_back ( i ) ; } } int sz = ret.size ( ) ; printf ( "%d\n" , sz ) ; for ( i = 0 ; i < sz ; i ++ ) { printf ( "%d " , ret[ i ] ) ; } printf ( "\n" ) ; } int main ( ) { input ( ) ; solve ( ) ; return 0 ; }

Compilation message (stderr)

bootfall.cpp: In function 'void input()':
bootfall.cpp:19:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d" , &n ) ;
                         ^
bootfall.cpp:24:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ 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...
#Verdict Execution timeMemoryGrader output
Fetching results...