結果

問題 No.2499 Sum of Products of Sums
ユーザー pockynypockyny
提出日時 2023-10-28 16:29:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 809 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 118,104 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-28 16:30:05
合計ジャッジ時間 7,447 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 10 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 437 ms
4,348 KB
testcase_14 AC 376 ms
4,348 KB
testcase_15 AC 261 ms
4,348 KB
testcase_16 AC 502 ms
4,348 KB
testcase_17 AC 787 ms
4,348 KB
testcase_18 AC 809 ms
4,348 KB
testcase_19 AC 789 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/convolution>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;
using mint = modint998244353;
int a[1010],b[1010];
mint fa[1010];
int main(){
    int i,j,h,w; cin >> h >> w;
    vector<mint> f = {1};
    fa[0] = 1;
    for(i=1;i<=w;i++) fa[i] = fa[i - 1]*i;
    for(i=0;i<h;i++){
        cin >> a[i] >> b[i];
        mint val1 = w + b[i],val2 = w + a[i] - 1;
        mint pr1 = 1,pr2 = 1;
        for(j=1;j<=w;j++){
            pr1 *= val1; pr1 /= j;
            pr2 *= val2; pr2 /= j;
            val1--; val2--;
        }
        vector<mint> g;
        g.push_back(pr1 - pr2);
        for(j=1;j<=w;j++){
            pr1 *= val1; pr1 /= (w + j);
            pr2 *= val2; pr2 /= (w + j);
            val1--; val2--;
            g.push_back((pr1 - pr2)/fa[j]);
        }
        // for(mint x:g) cout << x.val() << " ";
        // cout << endl;
        f = convolution(f,g);
        f.resize(w + 1);
    }
    cout << (fa[w]*f[w]).val() << endl;
}
0