結果

問題 No.2141 Enumeratest
ユーザー みここみここ
提出日時 2023-01-15 20:48:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 3,790 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 76,492 KB
実行使用メモリ 10,944 KB
最終ジャッジ日時 2023-08-28 13:02:47
合計ジャッジ時間 4,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 12 ms
4,828 KB
testcase_03 AC 39 ms
10,768 KB
testcase_04 AC 77 ms
10,944 KB
testcase_05 AC 40 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 16 ms
6,216 KB
testcase_09 AC 11 ms
4,940 KB
testcase_10 AC 24 ms
7,560 KB
testcase_11 AC 36 ms
10,032 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 10 ms
4,748 KB
testcase_14 AC 36 ms
10,044 KB
testcase_15 AC 22 ms
7,060 KB
testcase_16 AC 28 ms
8,108 KB
testcase_17 AC 50 ms
7,560 KB
testcase_18 AC 43 ms
5,144 KB
testcase_19 AC 63 ms
9,096 KB
testcase_20 AC 45 ms
6,304 KB
testcase_21 AC 48 ms
6,216 KB
testcase_22 AC 33 ms
5,180 KB
testcase_23 AC 22 ms
4,888 KB
testcase_24 AC 46 ms
10,364 KB
testcase_25 AC 15 ms
5,696 KB
testcase_26 AC 37 ms
4,380 KB
testcase_27 AC 44 ms
5,676 KB
testcase_28 AC 49 ms
5,156 KB
testcase_29 AC 28 ms
4,392 KB
testcase_30 AC 62 ms
8,636 KB
testcase_31 AC 43 ms
6,868 KB
testcase_32 AC 53 ms
8,092 KB
testcase_33 AC 39 ms
5,888 KB
testcase_34 AC 52 ms
8,992 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 50 ms
5,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <vector>
using namespace std;

struct dynamic_modint
{
    using mint = dynamic_modint;

public:
    int val;

    dynamic_modint() : val(0) {}

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

    static void set_mod(int m)
    {
        MOD = m;
    }

    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 int MOD;
    static int mod()
    {
        return MOD;
    }
};

int dynamic_modint::MOD = 1000000007;

using mint = dynamic_modint;

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;
};

int main()
{
    mint::set_mod(998244353);
    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