Submission #678396

#TimeUsernameProblemLanguageResultExecution timeMemory
678396Ahmed57Bootfall (IZhO17_bootfall)C++14
65 / 100
1094 ms3600 KiB
#include <bits/stdc++.h> using namespace std; long long dp[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 = sum;j>=arr[i];j--){ dp[j]+=dp[j-arr[i]]; if(dp[j]>=1e18)dp[j]%=mod; } } if(sum%2||(!dp[sum/2])){ cout<<"0"; return 0; } vector<int> v; for(int i = (arr[0]%2?1:2);i<=sum;i+=2){v.push_back(i);} for(int it = 0;it<n;it++){ for(int j = arr[it];j<=sum;j++){ dp[j]-=dp[j-arr[it]]; dp[j]%=mod; if(dp[j]<0){dp[j]%=mod;dp[j]+=mod;dp[j]%=mod;} } vector<int> c; for(auto j:v){ if((sum-arr[it]+j)%2){ continue; } int ne = sum-arr[it]+j; int d = 0; if(ne/2<=sum)d = (dp[ne/2]>0); else break; if(j<=ne/2&&(ne/2)-j<=sum)d|=(dp[(ne/2)-j]>0); if(d==1)c.push_back(j); } v = c; for(int j = sum;j>=arr[it];j--){ dp[j]+=dp[j-arr[it]]; if(dp[j]>=1e18)dp[j]%=mod; } } 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...