Submission #1128259

#TimeUsernameProblemLanguageResultExecution timeMemory
1128259the_ZHERBootfall (IZhO17_bootfall)C++20
100 / 100
786 ms4792 KiB
#include <bits/stdc++.h> #define int long long #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const int N = (500*500)+1; const int inf = 1e9; const int mod=1e9+7; struct edge{ int x,y,c; }; vector<int>v; int dp[N]; vector<int>v1; int ok[N]; signed main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); boost int n; cin>>n; v.push_back(0); int sum=0; for(int i=1;i<=n;i++){ int x; cin>>x; sum+=x; v.push_back(x); } dp[0]=1; for(int i=1;i<=n;i++){ for(int j=sum;j>=v[i];j--){ dp[j]=(dp[j]+dp[j-v[i]])%mod; } } if(sum%2==1||dp[sum/2]==0){ cout<<0; return 0; } int cnt=sum; for(int i=1;i<=n;i++){ for(int j=v[i];j<=sum;j++){ dp[j]=(dp[j]-dp[j-v[i]]+mod)%mod; } for(int j=1;j<=sum;j++){ if((sum-v[i]+j)%2==1||dp[(sum-v[i]+j)/2]==0){ if(ok[j]==0){ ok[j]=1; cnt--; } } } for(int j=sum;j>=v[i];j--){ dp[j]=(dp[j]+dp[j-v[i]])%mod; } } cout<<cnt<<"\n"; for(int i=1;i<=sum;i++){ if(ok[i]==0){ 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...