# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
500858 | EliteCallsYou | Bootfall (IZhO17_bootfall) | C++17 | 0 ms | 292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
using namespace std ;
//############################################################################
# define read(a)/**/for(int i=0;i<int(sizeof(a)/sizeof(a[0]));i++){cin>>a[i];}
# define print(x)/**/for(auto zx:x){cout<<zx<<' ';}
const char* tochar(string a){return a.c_str();}
void files(){freopen("planting.in","r",stdin);freopen("planting.out","w",stdout);}
void speed(){ios_base::sync_with_stdio(false);cin.tie(0);}
long long gcd(long long a,long long b){if(!b){return a;}a%=b;return gcd(b,a);}
long long lcm(long long a,long long b){return a /gcd(a,b) * b;}
//###########################################################################
const int N = 3e5 + 5 ;
const long long MOD = 1e17+7 ;
//###########################################################################
void hack(){}
//###########################################################################
int main(){
int n, sum = 0 ; cin >> n ;
int ar[n+1] ;
for ( int i = 1 ; i <= n ; i ++ ){
cin >> ar[i] ;
sum += ar[i] ;
}
if ( sum%2 ){
cout << "0\n";
return 0 ;
}
bool dp[n+1][sum+1] = {false} ;
for ( int i = 0 ; i <= n ; i ++ ){
dp[i][0] = true ;
for ( int it = 1 ; it <= n ; it ++ ){
if ( it == i ){continue;}
for ( int j = sum-ar[it] ; j > -1 ; j -- ){
if ( dp[i][j] ){
dp[i][j+ar[it]] = true ;
}
}
}
}
if ( !dp[0][sum/2] ){
cout << "0\n" ;
return 0 ;
}
vector < int > ans ;
for ( int cur = 1 ; cur <= sum ; cur ++ ){
bool ok = true ;
for ( int j = 1 ; j <= n ; j ++ ){
int s = sum-ar[j]+cur ;
if ( s%2 || s < 0 ){
ok = false ;
break ;
}
if ( !dp[j][s/2] ){
ok = false ;
break ;
}
}
if ( ok ){
ans.push_back(cur) ;
}
}
cout << ans.size() << '\n' ;
for ( auto it : ans ){
cout << it << ' ' ;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |