結果

問題 No.2141 Enumeratest
ユーザー みここみここ
提出日時 2023-01-14 04:03:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 3,692 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 75,916 KB
実行使用メモリ 11,132 KB
最終ジャッジ日時 2023-08-26 08:12:09
合計ジャッジ時間 3,700 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 6 ms
4,892 KB
testcase_03 AC 17 ms
10,884 KB
testcase_04 AC 23 ms
11,132 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 8 ms
5,940 KB
testcase_09 AC 5 ms
4,836 KB
testcase_10 AC 11 ms
7,612 KB
testcase_11 AC 16 ms
10,140 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,624 KB
testcase_14 AC 15 ms
10,048 KB
testcase_15 AC 10 ms
6,952 KB
testcase_16 AC 12 ms
8,252 KB
testcase_17 AC 15 ms
7,616 KB
testcase_18 AC 10 ms
5,240 KB
testcase_19 AC 18 ms
9,084 KB
testcase_20 AC 13 ms
6,220 KB
testcase_21 AC 13 ms
6,280 KB
testcase_22 AC 9 ms
5,224 KB
testcase_23 AC 8 ms
4,980 KB
testcase_24 AC 17 ms
10,280 KB
testcase_25 AC 7 ms
5,676 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 12 ms
5,632 KB
testcase_28 AC 12 ms
5,148 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 18 ms
8,604 KB
testcase_31 AC 13 ms
6,860 KB
testcase_32 AC 17 ms
8,008 KB
testcase_33 AC 11 ms
5,892 KB
testcase_34 AC 17 ms
8,988 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 13 ms
5,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
typedef long long ll;

template <int MOD>
struct static_modint
{
    using mint = static_modint;

public:
    int val;

    static_modint() : val(0) {}

    static_modint(long long v)
    {
        if (abs(v) >= mod())
        {
            v %= mod();
        }
        if (v < 0)
        {
            v += mod();
        }
        val = v;
    }

    mint &operator++()
    {
        val++;
        if (val == mod())
        {
            val = 0;
        }
        return *this;
    }

    mint &operator--()
    {
        if (val == 0)
        {
            val = mod();
        }
        val--;
        return *this;
    }

    mint &operator+=(const mint &x)
    {
        val += x.val;
        if (val >= mod())
        {
            val -= mod();
        }
        return *this;
    }

    mint &operator-=(const mint &x)
    {
        val -= x.val;
        if (val < 0)
        {
            val += mod();
        }
        return *this;
    }

    mint &operator*=(const mint &x)
    {
        val = (int)((long long)val * x.val % mod());
        return *this;
    }

    mint &operator/=(const mint &x)
    {
        *this *= x.inv();
        return *this;
    }

    mint operator-()
    {
        return mint() - *this;
    }

    mint pow(long long n) const
    {
        mint x = 1, r = *this;
        while (n)
        {
            if (n & 1)
            {
                x *= r;
            }
            r *= r;
            n >>= 1;
        }
        return x;
    }

    mint inv() const
    {
        return pow(mod() - 2);
    }

    friend mint operator+(const mint &x, const mint &y)
    {
        return mint(x) += y;
    }

    friend mint operator-(const mint &x, const mint &y)
    {
        return mint(x) -= y;
    }

    friend mint operator*(const mint &x, const mint &y)
    {
        return mint(x) *= y;
    }

    friend mint operator/(const mint &x, const mint &y)
    {
        return mint(x) /= y;
    }

    friend bool operator==(const mint &x, const mint &y)
    {
        return x.val == y.val;
    }

    friend bool operator!=(const mint &x, const mint &y)
    {
        return x.val != y.val;
    }

    friend std::ostream &operator<<(std::ostream &os, const mint &x)
    {
        return os << x.val;
    }

    friend std::istream &operator>>(std::istream &is, mint &x)
    {
        long long v;
        is >> v;
        x = mint(v);
        return is;
    }

private:
    static constexpr int mod()
    {
        return MOD;
    }
};

template <typename M>
struct combination
{
public:
    combination(int maxn) : maxn(maxn)
    {
        fact.resize(maxn + 1);
        ifact.resize(maxn + 1);
        fact[0] = 1;
        for (int i = 1; i <= maxn; i++)
        {
            fact[i] = fact[i - 1] * i;
        }
        ifact[maxn] = fact[maxn].inv();
        for (int i = maxn - 1; i >= 0; i--)
        {
            ifact[i] = ifact[i + 1] * (i + 1);
        }
    }

    M operator()(int n, int k)
    {
        assert(n <= maxn);
        if (k > n || k < 0)
        {
            return 0;
        }
        return fact[n] * ifact[k] * ifact[n - k];
    }

private:
    int maxn;
    std::vector<M> fact;
    std::vector<M> ifact;
};

using mint = static_modint<998244353>;

int main()
{
    int n, m;
    cin >> n >> m;
    combination<mint> com(m);
    int s = m;
    mint ans = 1;
    for (int i = 0; i < n; i++)
    {
        if (i < m % n)
        {
            ans *= com(s, m / n + 1);
            s -= m / n + 1;
        }
        else
        {
            ans *= com(s, m / n);
            s -= m / n;
        }
    }
    cout << ans << endl;
}
0