結果

問題 No.2499 Sum of Products of Sums
ユーザー hitonanodehitonanode
提出日時 2024-03-10 20:27:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 2,770 ms
コンパイル使用メモリ 142,980 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-10 20:27:34
合計ジャッジ時間 6,122 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 6 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 6 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 237 ms
6,676 KB
testcase_14 AC 207 ms
6,676 KB
testcase_15 AC 152 ms
6,676 KB
testcase_16 AC 260 ms
6,676 KB
testcase_17 AC 424 ms
6,676 KB
testcase_18 AC 425 ms
6,676 KB
testcase_19 AC 423 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

#include <atcoder/modint>
#include <atcoder/convolution>
using mint = atcoder::modint998244353;

// [x^B] 1/(m!) * (x / (1 - x)^2 )^m (1 / (1 - x))^(W - m + 1) を m = 0, ..., W で列挙
// [x^B] 1/m! * x^m / (1 - x)^(W + 1 + m)
// 1/m! [x^(B - m)] 1 / (1 - x)^(W + 1 + m)
// 1/m! Comb(B + W, W + m)
vector<mint> gen(int W, int B) {
    vector<mint> ret(W + 1);
    mint num = 1, den = 1;
    REP(_, W) {
        num *= B + W - _;
        den *= W - _;
    }
    ret.at(0) = num / den;
    FOR(m, 1, W + 1) {
        num *= B + W - W + 1 - m;
        den *= W + m;
        den *= m;
        ret.at(m) = num / den;
    }
    return ret;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int H, W;
    cin >> H >> W;

    vector<mint> dp{1};

    for (int i = 0; i < H; ++i) {
        int a, b;
        cin >> a >> b;
        auto f = gen(W, b);
        auto g = gen(W, a - 1);
        REP(i, g.size()) f.at(i) -= g.at(i);

        dp = atcoder::convolution(dp, f);
        dp.resize(W + 1);
    }

    mint ret = dp.back();
    FOR(i, 1, W + 1) ret *= i;

    cout << ret.val() << '\n';
}
0