Submission #50420612


Source Code Expand

#include <bits/stdc++.h>

typedef long long valueType;
typedef std::vector<valueType> ValueVector;
typedef std::vector<ValueVector> ValueMatrix;
typedef std::vector<ValueMatrix> ValueCube;
typedef std::string string;
typedef std::vector<string> StringVector;
typedef std::vector<bool> bitset;
typedef std::vector<bitset> BitMatrix;
typedef std::pair<valueType, valueType> ValuePair;
typedef std::vector<ValuePair> PairVector;
typedef std::vector<PairVector> PairMatrix;
typedef std::tuple<valueType, valueType, valueType> ValueTuple;
typedef std::vector<ValueTuple> TupleVector;
typedef std::vector<TupleVector> TupleMatrix;
typedef std::set<valueType> ValueSet;

namespace MODINT_WITH_FIXED_MOD {
    constexpr valueType MOD = 998244353;

    template<typename T1, typename T2>
    void Inc(T1 &a, T2 b) {
        a = a + b;

        if (a >= MOD)
            a -= MOD;
    }

    template<typename T1, typename T2>
    void Dec(T1 &a, T2 b) {
        a = a - b;

        if (a < 0)
            a += MOD;
    }

    template<typename T1, typename T2>
    T1 sum(T1 a, T2 b) {
        return a + b >= MOD ? a + b - MOD : a + b;
    }

    template<typename T1, typename T2>
    T1 sub(T1 a, T2 b) {
        return a - b < 0 ? a - b + MOD : a - b;
    }

    template<typename T1, typename T2>
    T1 mul(T1 a, T2 b) {
        return (long long) a * b % MOD;
    }

    template<typename T1, typename T2>
    void Mul(T1 &a, T2 b) {
        a = (long long) a * b % MOD;
    }

    template<typename T1, typename T2>
    T1 pow(T1 a, T2 b) {
        T1 result = 1;

        while (b > 0) {
            if (b & 1)
                Mul(result, a);

            Mul(a, a);
            b = b >> 1;
        }

        return result;
    }
} // namespace MODINT_WITH_FIXED_MOD

using namespace MODINT_WITH_FIXED_MOD;

class BinomialCoefficient {
private:
    valueType N;
    ValueVector Fact_, InvFact;

public:
    BinomialCoefficient() = default;

    BinomialCoefficient(valueType n) : N(n), Fact_(N + 1, 1), InvFact(N + 1, 1) {
        for (valueType i = 1; i <= N; ++i)
            Fact_[i] = mul(Fact_[i - 1], i);

        InvFact[N] = pow(Fact_[N], MOD - 2);

        for (valueType i = N - 1; i >= 0; --i)
            InvFact[i] = mul(InvFact[i + 1], i + 1);
    }

    valueType operator()(valueType n, valueType m) const {
        if (n < 0 || m < 0 || n < m)
            return 0;

        if (m > N)
            throw std::out_of_range("BinomialCoefficient::operator() : m > N");

        if (n <= N)
            return mul(Fact_[n], mul(InvFact[m], InvFact[n - m]));

        valueType result = 1;

        for (valueType i = 0; i < m; ++i)
            Mul(result, n - i);

        Mul(result, InvFact[m]);

        return result;
    }

    valueType Fact(valueType n) const {
        return Fact_[n];
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    valueType N, K, L;

    std::cin >> N >> K >> L;

    valueType const Limit = N - K + 1;

    BinomialCoefficient const C(N);

    valueType Ans = 1;

    Mul(Ans, C(L, Limit));
    Mul(Ans, C.Fact(Limit));

    for (valueType i = Limit + 1; i <= N; ++i)
        Mul(Ans, L - Limit + 1);

    std::cout << Ans << std::endl;

    return 0;
}

Submission Info

Submission Time
Task B - AtCoder Language
User UserUnauthorized
Language C++ 20 (gcc 12.2)
Score 500
Code Size 3411 Byte
Status AC
Exec Time 11 ms
Memory 11060 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 30
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 3412 KiB
in02.txt AC 1 ms 3472 KiB
in03.txt AC 4 ms 5668 KiB
in04.txt AC 5 ms 6432 KiB
in05.txt AC 4 ms 5720 KiB
in06.txt AC 5 ms 6404 KiB
in07.txt AC 11 ms 11056 KiB
in08.txt AC 10 ms 11060 KiB
in09.txt AC 10 ms 10824 KiB
in10.txt AC 10 ms 11056 KiB
in11.txt AC 1 ms 3376 KiB
in12.txt AC 1 ms 3388 KiB
in13.txt AC 1 ms 3388 KiB
in14.txt AC 1 ms 3448 KiB
in15.txt AC 4 ms 5608 KiB
in16.txt AC 4 ms 5720 KiB
in17.txt AC 4 ms 5616 KiB
in18.txt AC 4 ms 5676 KiB
in19.txt AC 9 ms 11000 KiB
in20.txt AC 9 ms 10992 KiB
in21.txt AC 9 ms 10896 KiB
in22.txt AC 9 ms 10988 KiB
in23.txt AC 1 ms 3404 KiB
in24.txt AC 1 ms 3376 KiB
in25.txt AC 10 ms 10904 KiB
in26.txt AC 10 ms 10996 KiB
sample-01.txt AC 1 ms 3516 KiB
sample-02.txt AC 1 ms 3600 KiB
sample-03.txt AC 1 ms 3592 KiB
sample-04.txt AC 11 ms 10952 KiB