Submission #522953

#TimeUsernameProblemLanguageResultExecution timeMemory
522953nickmet2004Bootfall (IZhO17_bootfall)C++11
100 / 100
577 ms3440 KiB
#include<bits/stdc++.h> using namespace std; const int N = 501; int n , a[N] , dp[N*N+505] , ans[N * N]; int main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; int s =0; for(int i = 0;i < n; ++i)cin >> a[i] ,s+=a[i]; dp[0] = 1; for(int i = 0; i < n; ++i){ for(int j = s; j>= a[i]; --j)dp[j] += dp[j - a[i]]; } if(s & 1 || dp[s/2]==0){ cout << 0; return 0; } vector<int> y; for(int i = 0; i <n; ++i){ for(int j = a[i]; j <= s; ++j)dp[j] -= dp[j - a[i]]; for(int j = 1; j<= s; ++j){ int z = s - a[i] + j; //cout << j << " " << S << endl; if(z&1 || !dp[z/2])continue; ans[j]++; if(ans[j]==n)y.emplace_back(j); } for(int j = s; j >= a[i]; --j)dp[j] += dp[j-a[i]]; } cout << y.size()<<endl; for(int x : y)cout << x << " "; //cout << dp[s/2]; }
#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...