46042023-03-30 11:14:22Error42Játék (50 pont)cpp17Accepted 50/5039ms4160 KiB
#include <iostream>

using namespace std;

using ll = long long;

template <ll M>
struct modular {
    ll val;

    // n >= 0
    modular(const ll n) {
        if (n < M)
            val = n;
        else if (n < 2 * M)
            val = n - M;
        else
            val = n % M;
    }

    [[nodiscard]] modular operator +(const modular& rhs) const {
        return val + rhs.val;
    }

    [[nodiscard]] modular operator -(const modular& rhs) const {
        return val + M - rhs.val;
    }

    [[nodiscard]] modular operator *(const modular& rhs) const {
        return val * rhs.val;
    }

    // p >= 0
    [[nodiscard]] modular pow(const ll& p) const {
        if (p == 0)
            return 1;

        if (p % 2 == 0)
            return (*this * *this).pow(p / 2);
        else
            return *this * pow(p - 1);
    }

    [[nodiscard]] modular inv() const {
        return pow(M - 2);
    }

    [[nodiscard]] modular operator /(const modular& rhs) const {
        return *this * rhs.inv();
    }

    modular& operator +=(const modular& rhs) {
        return *this = *this + rhs;
    }

    modular& operator -=(const modular& rhs) {
        return *this = *this - rhs;
    }

    modular& operator *=(const modular& rhs) {
        return *this = *this * rhs;
    }

    modular& operator /=(const modular& rhs) {
        return *this = *this / rhs;
    }

    explicit operator ll() const {
        return val;
    }
};

template <ll M>
ostream& operator<<(ostream& os, const modular<M>& modular) {
    cout << modular.val;
    return os;
}

using mod = modular<1'000'000'007>;

mod nck(ll const& n, ll const& k) {
    mod ans = 1;

    for (ll i = n - k + 1; i <= n; i++)
        ans *= i;

    for (ll i = 2; i <= k; i++)
        ans /= i;

    return ans;
}

int main() {
    ll b, c;
    cin >> b >> c;

    cout << nck(2 * c - b - 1, c - b) - nck(2 * c - b - 1, c - b - 1) << "\n";
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1876 KiB
2Accepted0/02ms2120 KiB
3Accepted2/23ms2328 KiB
4Accepted3/32ms2416 KiB
5Accepted3/33ms2548 KiB
6Accepted3/33ms2752 KiB
7Accepted3/33ms2840 KiB
8Accepted3/33ms2964 KiB
9Accepted3/33ms3024 KiB
10Accepted3/33ms3248 KiB
11Accepted3/33ms3468 KiB
12Accepted3/33ms3564 KiB
13Accepted3/33ms3692 KiB
14Accepted3/339ms3732 KiB
15Accepted3/314ms3736 KiB
16Accepted3/316ms3864 KiB
17Accepted3/326ms4108 KiB
18Accepted3/313ms4156 KiB
19Accepted3/321ms4160 KiB