結果

問題 No.2048 L(I+D)S
ユーザー novaandcabralnovaandcabral
提出日時 2024-04-13 22:31:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,548 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 71,756 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-13 22:31:30
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,812 KB
testcase_01 AC 6 ms
6,940 KB
testcase_02 AC 8 ms
6,940 KB
testcase_03 AC 7 ms
6,940 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 AC 7 ms
6,944 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 49 ms
6,940 KB
testcase_09 AC 22 ms
6,940 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 55 ms
6,940 KB
testcase_12 AC 32 ms
6,944 KB
testcase_13 AC 20 ms
6,940 KB
testcase_14 AC 22 ms
6,944 KB
testcase_15 AC 12 ms
6,940 KB
testcase_16 AC 56 ms
6,944 KB
testcase_17 AC 58 ms
6,940 KB
testcase_18 AC 56 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

const long long MOD = 998244353LL;

struct ModInt {
    long long x;

    ModInt(long long _x = 0) : x((_x % MOD + MOD) % MOD) {}

    ModInt operator+(const ModInt& other) const {
        return ModInt(x + other.x);
    }

    ModInt operator-(const ModInt& other) const {
        return ModInt(x - other.x);
    }

    ModInt operator*(const ModInt& other) const {
        return ModInt(x * other.x);
    }

    ModInt operator/(const ModInt& other) const {
        return *this * other.inv();
    }

    ModInt pow(long long exp) const {
        if (exp == 0LL) return ModInt(1LL);
        ModInt a = pow(exp >> 1);
        a = a * a;
        if (exp & 1LL) return *this * a;
        return a;
    }

    ModInt inv() const {
        return pow(MOD - 2);
    }

    bool operator==(const ModInt& other) const {
        return x == other.x;
    }

    bool operator!=(const ModInt& other) const {
        return !(*this == other);
    }
};

int main() {
    int n;
    cin >> n;

    const int facSize = 300000;
    vector<ModInt> fac(facSize);
    fac[0] = ModInt(1);
    for (int i = 1; i < facSize; ++i) {
        fac[i] = fac[i - 1] * ModInt(i);
    }

    auto helper = [&](int n, int m) -> ModInt {
        ModInt r = fac[n + m] / (fac[n - 2] * fac[m - 2] * ModInt(n) * ModInt(m) * ModInt(n + m - 1));
        return r * r;
    };

    ModInt ans(0);
    for (int k = 2; k <= n - 2; ++k) {
        ans = ans + helper(n - k, k);
    }

    cout << ans.x << endl;

    return 0;
}
0