Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define taskname "BALANCE"
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <algorithm>
- #include <array>
- #include <iomanip>
- using namespace std;
- using lli = long long;
- using ld = long double;
- const int maxN = 100;
- const int maxM = maxN * (maxN + 1) / 2;
- const lli Radix = 1e18;
- const int gd = 18;
- const int nd = 3;
- int n, m, k;
- struct TNumber
- {
- array<lli, nd> d; //d[0] + d[1] * Radix + d[2] * Radix ^ 2.
- TNumber& operator = (lli x)
- {
- fill(d.begin(), d.end(), 0);
- d[0] = x;
- return *this;
- }
- TNumber operator + (const TNumber& other) const
- {
- TNumber res;
- lli carry = 0LL;
- for (int i = 0; i < nd; ++i)
- {
- carry += d[i] + other.d[i];
- res.d[i] = carry % Radix;
- carry /= Radix;
- }
- return res;
- }
- void Print() const
- {
- int i = nd - 1;
- while (i > 0 && d[i] == 0) --i;
- cout << d[i];
- for (--i; i >= 0; --i)
- cout << setw(gd) << setfill('0') << d[i];
- }
- };
- TNumber f[maxM + 1], g[maxM + 1];
- void ReadInput()
- {
- cin >> n >> m;
- k = n * (n + 1) / 2;
- }
- void Solve()
- {
- f[0] = 1;
- for (int y = 1; y <= k; ++y)
- f[y] = 0;
- for (int x = 1; x <= n; ++x)
- {
- for (int y = 0; y <= k; ++y)
- {
- g[y] = f[y] + f[abs(x - y)];
- if (x + y <= k) g[y] = g[y] + f[x + y];
- }
- swap(f, g);
- }
- f[m].Print();
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- //freopen(taskname".INP", "r", stdin);
- //freopen(taskname".OUT", "w", stdout);
- ReadInput();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement