Advertisement
Helicator

bcatalan.cpp

Dec 13th, 2021
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define vi vector<int>
  6. #define ii pair<int,int>
  7. #define fi first
  8. #define sc second
  9. #define pb push_back
  10. #define stoi stoll
  11. #define popcnt __builtin_popcount
  12. #define getbit(x, k) ((x >> k) & 1)
  13. #define all(x) (x).begin(),(x).end()
  14. #define FOR(i,j,k) for(int i=j; i<k; i++)
  15. #define look(a) cerr <<#a<<": "<<a<<endl;
  16. #define look2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
  17.  
  18. const int BASE = 1e4;
  19.  
  20. void fix(vi &a){
  21.     a.push_back(0);
  22.     FOR(i,0,a.size()-1){
  23.         a[i+1] += a[i] / BASE;
  24.         a[i] %= BASE;
  25.         if (a[i] < 0){
  26.             a[i] += BASE;
  27.             a[i+1]--;
  28.         }
  29.     }
  30.     while (a.size() >= 2 && a.back() == 0) a.pop_back();
  31. }
  32.  
  33. vi operator*(const vi &a, const vi &b){
  34.     vi c(a.size() + b.size() + 1);
  35.     FOR(i,0,a.size())
  36.         FOR(j,0,b.size()){
  37.             c[i+j] += a[i]*b[j];
  38.             c[i+j+1] += c[i+j] / BASE;
  39.             c[i+j] %= BASE;
  40.         }
  41.     return fix(c), c;
  42. }
  43.  
  44. vi to_vi(int x){
  45.     assert(x < BASE);
  46.     return vi(1,x);
  47. }
  48.  
  49. vi operator+(vi a, const vi &b){
  50.     a.resize(max(a.size(), b.size()));
  51.     FOR(i,0,b.size())
  52.         a[i] += b[i];
  53.     return fix(a), a;
  54. }
  55.  
  56. vi operator*(vi a, int x){
  57.     assert(x < BASE);
  58.     FOR(i,0,a.size())
  59.         a[i] *= x;
  60.     return fix(a), a;
  61. }
  62.  
  63. vi operator/(vi a, int x) {  // x < BASE
  64.     assert(x < BASE);
  65.     for (int i = (int)a.size() - 1, r = 0; i >= 0; --i, r %= x) {
  66.         r = r * BASE + a[i];
  67.         a[i] = r / x;
  68.     }
  69.     return fix(a), a;
  70. }
  71.  
  72. ostream &operator<<(ostream &cout, const vi &a) {
  73.     cout << a.back();
  74.     for (int i = (int)a.size() - 2; i >= 0; i--)
  75.         cout << a[i];
  76.     return cout;
  77. }
  78.  
  79. void solve()
  80. {
  81.     int n;
  82.     cin >> n;
  83.  
  84.     vi f[n+2];
  85.     f[0] = f[1] = to_vi(1);
  86.     FOR(i,1,n+1){
  87.         // look(i);
  88.         // f[i] = to_vi(0);
  89.         // FOR(j,0,i)
  90.         //  f[i] = f[i] + f[j] * f[i-j-1];
  91.         f[i+1] = (to_vi(4*i-2)*f[i])/(i+1);
  92.     }
  93.  
  94.     cout << f[n+1];
  95. }
  96.  
  97. signed main()
  98. {
  99.     cin.tie(0)->sync_with_stdio(0);
  100.     freopen("in", "r", stdin);
  101.     freopen("out", "w", stdout);
  102.     int T = 1;
  103.     // cin >> T;
  104.     while (T--) {
  105.         solve();
  106.         cout << '\n';
  107.     }
  108.     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement