Advertisement
ivnikkk

Untitled

Dec 25th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <vector>
  2. #include<iostream>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <iomanip>
  6. #include <fstream>
  7. #include <string>
  8. #include <set>
  9. #include <deque>
  10. #include <queue>
  11. #include <map>
  12. #include <bitset>
  13. #include <random>
  14. #include <cassert>
  15. #include <unordered_map>
  16. #include <unordered_set>
  17. #include<math.h>
  18. using namespace std;
  19. typedef unsigned int ui;
  20. typedef long long ll;
  21. typedef unsigned long long ull;
  22. typedef long double ld;
  23. #define endl "\n"
  24. #define all(a) a.begin(), a.end()
  25. #define allr(a) a.rbegin(), a.rend()
  26. #define pb push_back
  27. #define pikachu push_back
  28. #define F first
  29. #define S second
  30. void solve() {
  31. ll n,sum_now=0;
  32. cin >> n;
  33. vector<ll> a(n),dp(30000,0);
  34. dp[0] = 1;
  35. for (ll i = 0; i < n; i++){
  36. cin >> a[i];
  37. for (ll j = sum_now; j >= 0; j--)
  38. dp[j + a[i]] += dp[j];
  39. sum_now += a[i];
  40. }
  41. if (sum_now&1){
  42. cout << 0 << endl;
  43. return;
  44. }
  45. if (!dp[sum_now / 2]) {
  46. cout << 0 << endl;
  47. return;
  48. }
  49. vector<bool> ban_ans(25001, false),used(501,false);
  50. for (ll i = 0; i < n; i++) {
  51. if (!used[a[i]]) {
  52. used[a[i]] = true;
  53. sum_now -= a[i];
  54. for (ll j = 0; j <= sum_now; j++)
  55. dp[j + a[i]] -= dp[j];
  56. for (ll j = 1; j <= 25000; j++) {
  57. if ((sum_now + j) & 1)
  58. ban_ans[j] = true;
  59. if (!dp[(sum_now + j) / 2])
  60. ban_ans[j] = true;
  61. }
  62. for (ll j = sum_now; j >= 0; j--)
  63. dp[j + a[i]] += dp[j];
  64. sum_now += a[i];
  65. }
  66. }
  67. vector <ll> ans;
  68. for (ll i = 1; i <= 25000; i++)
  69. if (!ban_ans[i]) ans.pb(i);
  70. cout << ans.size() << endl;
  71. for (ll& i : ans) {
  72. cout << i << ' ';
  73. }
  74. }
  75.  
  76. signed main() {
  77. ios_base::sync_with_stdio(false);
  78. cin.tie(nullptr);
  79. ll t = 1;
  80. //cin >> t;
  81. //cout << fixed << setprecision(18);
  82. while (t--) {
  83. solve();
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement