Submission #172877

#TimeUsernameProblemLanguageResultExecution timeMemory
172877LinusTorvaldsFanMoney (IZhO17_money)C++14
0 / 100
10 ms376 KiB
#include <bits/stdc++.h> using namespace std; const int maxn=500; const int maxc=500; const int maxw=maxc*maxn; bool available[maxn][maxn*maxc]; int main() { int n; cin>>n; vector<int>a(n); int sum=0; for(int i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } for(int i=0;i<=n;i++){ available[i][0]=true; for(int j=0;j<n;j++){ if(i==j)continue; for(int w=maxw-1;w>=0;w--){ if(available[i][w]){ available[i][w+a[j]]=true; } } } } if(sum&1){ cout<<0; return 0; } vector<int>ans; for(int x=0;x<=maxw;x++){ bool ok=true; if(!available[n][sum/2]){ ok=false; } for(int i=0;i<n;i++){ int nsum=sum-a[i]+x; if(nsum&1){ ok=false; break; } if(!available[i][nsum/2]){ ok=false; break; } } if(ok){ ans.push_back(x); } } cout<<ans.size()<<endl; for(auto x:ans)cout<<x<<" "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...