Submission #144036

#TimeUsernameProblemLanguageResultExecution timeMemory
144036The_WolfpackBootfall (IZhO17_bootfall)C++14
100 / 100
651 ms4596 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],vis[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=0;j<=KMAX-1;j++) { if(j-a[i]>=0) dp[j]-=dp[j-a[i]]; } /*for(int i=0;i<12;i++) cout<<dp[i]<< " "; cout<<endl;*/ memset(vis,0,sizeof(vis)); for(int j=1;j<=sum-a[i];j++) { if(!dp[j]) continue; //if(i==4) cout<<j<<"A"<<endl; if(!vis[abs(sum-2*j-a[i])]) moze[abs(sum-2*j-a[i])]++; vis[abs(sum-2*j-a[i])]=1; /*if(sum-j-a[i] > j) { if(!vis[sum-2*j-a[i]]) moze[sum-2*j-a[i]]++; vis[sum-2*j-a[i]]=1; //if(i==4) cout<<sum-2*j-a[i]<<"A"<<endl; //ans.push_back(sum-2*j-a[i]); } else { if(!vis[2*j+a[i]-sum]) moze[2*j+a[i]-sum]++; vis[2*j+a[i]-sum]=1; //if(i==4) cout<<2*j+a[i]-sum<<"A"<<endl; }*/ } for(int j=KMAX-1;j>=0;j--) { if(j-a[i]>=0) dp[j]+=dp[j-a[i]]; } /*for(int i=0;i<10;i++) cout<<moze[i]<<" "; cout<<endl;*/ } /*sort(ans.begin(),ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end());*/ for(int i=1;i<=KMAX-1;i++) if(moze[i]==n) ans.push_back(i); 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...