fork download
  1. #include <bits/stdc++.h>
  2.  
  3. typedef long long ll;
  4.  
  5. using namespace std;
  6.  
  7. ll n, x, a[40];
  8. vector<ll> le, ri;
  9.  
  10. vector<ll> f(int l, int r) {
  11. int m = r - l + 1;
  12. vector<ll> res;
  13. for (int i = 0; i < (1 << m); i++) {
  14. ll sum = 0;
  15. for (int j = 0; j < m; j++) {
  16. if (i & (1 << j)) {
  17. sum += a[l + j];
  18. }
  19. }
  20. res.push_back(sum);
  21. }
  22. return res;
  23. }
  24.  
  25.  
  26. int main() {
  27. cin.tie(0) -> sync_with_stdio(false), cout.tie(0);
  28. cin >> n >> x;
  29. for (int i = 0; i < n; i++) {
  30. cin >> a[i];
  31. }
  32. le = f(0, n / 2 - 1), ri = f(n / 2, n - 1);
  33. sort(le.begin(), le.end()), sort(ri.begin(), ri.end());
  34. ll ans = 0;
  35. for (auto i : le) {
  36. auto lo = lower_bound(ri.begin(), ri.end(), x - i);
  37. auto hi = upper_bound(ri.begin(), ri.end(), x - i);
  38. ans += hi - lo;
  39. }
  40. cout << ans << '\n';
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
1