結果

問題 No.1989 Pairing Multiset
ユーザー Drice27149Drice27149
提出日時 2022-06-25 00:21:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 54,928 KB
実行使用メモリ 33,920 KB
最終ジャッジ日時 2023-08-08 13:45:40
合計ジャッジ時間 2,231 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
33,908 KB
testcase_01 AC 63 ms
33,908 KB
testcase_02 AC 63 ms
33,908 KB
testcase_03 AC 64 ms
33,920 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 53 ms
33,852 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 60 ms
32,464 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 24 ms
12,880 KB
testcase_11 AC 40 ms
21,900 KB
testcase_12 AC 44 ms
23,748 KB
testcase_13 AC 61 ms
32,864 KB
testcase_14 AC 13 ms
7,588 KB
testcase_15 AC 11 ms
6,872 KB
testcase_16 AC 54 ms
29,020 KB
testcase_17 AC 7 ms
4,776 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 10 ms
6,336 KB
testcase_20 AC 64 ms
33,716 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