fork download
  1. #pragma GCC optimize("Ofast")
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. #define fi first
  8. #define se second
  9. #define pii pair<int, int>
  10.  
  11.  
  12. const int mod = 1e9 + 7;
  13. const int N = 1e6 + 5;
  14. int x[35], y[35], ans = 0, u, v, mid, n;
  15. map<pii, int> mp;
  16.  
  17.  
  18. void bt1(int i = 1, int tongx = 0, int tongy = 0) {
  19. if (i == mid + 1) {
  20. ++mp[{tongx, tongy}];
  21. return;
  22. }
  23. bt1(i + 1, tongx, tongy);
  24. bt1(i + 1, tongx + x[i], tongy + y[i]);
  25. }
  26. void bt2(int i = mid + 1, int tongx = 0, int tongy = 0) {
  27. // if (tongx > u || tongy > v) return;
  28. if (i == n + 1) {
  29. if (mp.find({u - tongx, v - tongy}) != mp.end()) ans += mp[{u - tongx, v - tongy}];
  30. return;
  31. }
  32. bt2(i + 1, tongx, tongy);
  33. bt2(i + 1, tongx + x[i], tongy + y[i]);
  34. }
  35. void output() {
  36. mid = n / 2;
  37. bt1();
  38. bt2();
  39. cout << ans;
  40. }
  41. void input() {
  42. cin >> n >> u >> v;
  43. for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i];
  44. }
  45. signed main () {
  46. if(fopen("", "r")) {
  47. freopen("", "r", stdin);
  48. freopen("", "w", stdout);
  49. }
  50.  
  51. ios_base::sync_with_stdio(false);
  52. cin.tie(nullptr); cout.tie(nullptr);
  53.  
  54. input();
  55. output();
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
1