Submission #405633

#TimeUsernameProblemLanguageResultExecution timeMemory
405633knightron0Bootfall (IZhO17_bootfall)C++14
100 / 100
360 ms5728 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN = 1e5 + 5; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; cin>>n; int a[n+2]; int sum = 0; for(int i=1;i<=n;i++){ cin>>a[i]; sum += a[i]; } int dp[sum+2]; clr(dp, 0); dp[0] = 1; for(int i=1;i<=n;i++){ for(int j=sum;j>=a[i];j--){ if(j >= a[i]) dp[j] += dp[j-a[i]]; } } if(dp[sum/2] == 0){ cout<<0<<endl; return 0; } int cnt[sum+2]; clr(cnt, 0); for(int i=1;i<=n;i++){ for(int j=a[i];j<=sum;j++){ dp[j] -= dp[j-a[i]]; } int mx = sum-a[i]; for(int j=0;j<=sum;j++){ int x = 2*j-mx; if(dp[j] != 0 && x >= 0){ cnt[x]++; } } for(int j=sum;j>=a[i];j--){ dp[j] += dp[j-a[i]]; } } vector<int> ans; for(int i=1;i<=sum;i++){ if(cnt[i] == n) ans.pb(i); } cout<<ans.size()<<endl; printvector(ans); 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...