Submission #144013

#TimeUsernameProblemLanguageResultExecution timeMemory
144013The_WolfpackBootfall (IZhO17_bootfall)C++14
0 / 100
7 ms1400 KiB
#include <bits/stdc++.h> using namespace std; const int NMAX=502; const int KMAX=502*502; int n,a[NMAX],dp[KMAX],moze[KMAX]; int main() { ios_base::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; int sum=0; for(int i=1;i<=n;i++) sum+=a[i]; dp[0]=1; for(int i=1;i<=n;i++) { for(int j=KMAX-1;j>=0;j--) { if(j-a[i]>=0) dp[j]+=dp[j-a[i]]; } } //for(int i=0;i<20;i++) cout<<dp[i]<<endl; if(sum&1 || !dp[sum/2]) { cout<<"0"<<endl; return 0; } vector<int> ans; for(int i=1;i<=n;i++) { for(int j=KMAX-1;j>=0;j--) { if(j-a[i]>=0) dp[j]-=dp[j-a[i]]; } for(int j=1;j<=sum-a[i];j++) { if(!dp[j] || !dp[sum-j-a[i]]) continue; if(sum-j-a[i] > j) { ans.push_back(sum-2*j-a[i]); } else { if(2*j+a[i]-sum>0)ans.push_back(2*j+a[i]-sum); } } for(int j=KMAX-1;j>=0;j--) { if(j-a[i]>=0) dp[j]+=dp[j-a[i]]; } } sort(ans.begin(),ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); cout<<ans.size()<<endl; for(int i:ans) cout<<i<<" "; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...