Submission #678375

#TimeUsernameProblemLanguageResultExecution timeMemory
678375Ahmed57Bootfall (IZhO17_bootfall)C++14
13 / 100
3 ms340 KiB
#include <bits/stdc++.h> using namespace std; long long dp[2*500*500+1]; long long mod = int(1e9+7); int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin>>n; int arr[n] , sum = 0; for(int i = 0;i<n;i++){ cin>>arr[i];sum+=arr[i]; } dp[0] = 1; for(int i = 0;i<n;i++){ for(int j = 2*sum;j>=arr[i];j--){ dp[j]+=dp[j-arr[i]]; if(dp[j]>=1e13)dp[j]%=mod; } } if(sum%2||(!dp[sum/2])){ cout<<"0"; return 0; } int su[sum+1]; for(int i = 1;i<=sum;i++)su[i] = 1; for(int it = 0;it<n;it++){ for(int j = arr[it];j<=2*sum;j++){ dp[j]-=dp[j-arr[it]]; if(dp[j]>=1e13)dp[j]%=mod; if(dp[j]<0){ dp[j]%=mod;dp[j]+=mod;dp[j]%=mod; } } for(int j = 1;j<=sum;j++){ if((sum-arr[it]+j)%2){ su[j]=0; } int ne = sum-arr[it]+j; int d = (dp[ne/2]>0); if(j<=ne/2)d|=(dp[(ne/2)-j]>0); su[j]&=d; } for(int j = 2*sum;j>=arr[it];j--){ dp[j]+=dp[j-arr[it]]; if(dp[j]>=1e13)dp[j]%=mod; } } vector<int> v; for(int i = 1;i<=sum;i++){ if(su[i])v.push_back(i); } cout<<v.size()<<"\n"; for(auto i:v)cout<<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...