結果

問題 No.1989 Pairing Multiset
ユーザー Drice27149Drice27149
提出日時 2022-06-25 00:21:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 56,320 KB
実行使用メモリ 34,688 KB
最終ジャッジ日時 2024-04-26 06:29:36
合計ジャッジ時間 2,187 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
34,560 KB
testcase_01 AC 67 ms
34,432 KB
testcase_02 AC 69 ms
34,560 KB
testcase_03 AC 68 ms
34,688 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 57 ms
34,432 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 63 ms
33,152 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 26 ms
13,820 KB
testcase_11 AC 44 ms
22,784 KB
testcase_12 AC 48 ms
24,320 KB
testcase_13 AC 66 ms
33,792 KB
testcase_14 AC 14 ms
8,192 KB
testcase_15 AC 12 ms
7,680 KB
testcase_16 AC 59 ms
29,824 KB
testcase_17 AC 7 ms
5,504 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 12 ms
7,296 KB
testcase_20 AC 70 ms
34,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <functional>
using namespace std;

const int mod = 998244353;

int power(int a, int b) {
    int res = 1;
    while (b) {
        if (b % 2) res = res * 1ll * a % mod;
        a = a * 1ll * a % mod;
        b /= 2;
    }
    return res;
}

void add(int& u, int v) {
    u += v;
    if (u >= mod) u -= mod;
}

struct ModInt {
    vector<int> f;
    vector<int> invf;
    ModInt(int n) {
        f.resize(n + 1);
        invf.resize(n + 1);
        f[0] = 1;
        for (int i = 1; i <= n; i++) f[i] = f[i - 1] * 1ll * i % mod;
        invf[n] = power(f[n], mod - 2);
        for (int i = n - 1; i >= 0; i--) invf[i] = invf[i + 1] * 1ll * (i + 1) % mod;
    }
    int comb(int n, int m) {
        if (m > n || m < 0) return 0;
        return f[n] * 1ll * invf[m] % mod * 1ll * invf[n - m] % mod;
    }
};

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    n *= 2;
    auto md = ModInt(2 * n);

    function<int(int, int)> comb = [&](int n, int m) {
        if (m > n || m < 0) return 0;
        if (n - m > m) return comb(n, n - m);
        int res = md.invf[n - m];
        // printf("time = %d\n", n - m);
        for (int i = n; i > m; i--) res = res * 1ll * i % mod;
        return res;
    };
    
    int ans = comb(m + n - 2, n - 1);
    ans = ans * 1ll * (m + n - 1) % mod * 1ll * (m + n) % mod;
    ans = ans * 1ll * power(n * 1ll * (n + 1) % mod, mod - 2) % mod;
    /*
    for (int i = 1; i <= m; i++) {
        int way = md.comb(m - i + n - 1, n - 1);
        // printf("i = %d, way = %d\n", i, way);
        add(ans, way * 1ll * i % mod);
    }*/
    ans = ans * 1ll * (n / 2) % mod;
    printf("%d\n", ans);
    return 0;
}
0