Submission #617208

#TimeUsernameProblemLanguageResultExecution timeMemory
617208HanksburgerBootfall (IZhO17_bootfall)C++17
100 / 100
327 ms2884 KiB
#include <bits/stdc++.h> using namespace std; int g[250005], f[250005], a[505]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, sum=0, ans=0; cin >> n; f[0]=1; for (int i=1; i<=n; i++) { cin >> a[i]; for (int j=sum; j>=0; j--) f[j+a[i]]+=f[j]; sum+=a[i]; } for (int i=1; i<=n; i++) { sum-=a[i]; for (int j=0; j<=sum; j++) { f[j+a[i]]-=f[j]; if (f[j]) g[max(0, j*2-sum)]++; } for (int j=sum; j>=0; j--) f[j+a[i]]+=f[j]; sum+=a[i]; } if (sum&1 || !f[sum/2]) { cout << 0; return 0; } for (int i=1; i<=sum; i++) if (g[i]==n) ans++; cout << ans << '\n'; for (int i=1; i<=sum; i++) if (g[i]==n) cout << i << ' '; 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...