結果

問題 No.2303 Frog on Grid
ユーザー t98slidert98slider
提出日時 2023-05-13 15:57:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 4,590 ms
コンパイル使用メモリ 235,048 KB
実行使用メモリ 12,752 KB
最終ジャッジ日時 2023-08-19 14:52:23
合計ジャッジ時間 5,519 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 45 ms
11,436 KB
testcase_03 AC 23 ms
6,876 KB
testcase_04 AC 44 ms
11,160 KB
testcase_05 AC 46 ms
11,828 KB
testcase_06 AC 23 ms
7,044 KB
testcase_07 AC 44 ms
10,700 KB
testcase_08 AC 45 ms
10,852 KB
testcase_09 AC 12 ms
5,188 KB
testcase_10 AC 22 ms
6,740 KB
testcase_11 AC 12 ms
4,888 KB
testcase_12 AC 24 ms
7,652 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 47 ms
12,588 KB
testcase_19 AC 48 ms
12,752 KB
testcase_20 AC 48 ms
12,540 KB
testcase_21 AC 48 ms
12,552 KB
testcase_22 AC 48 ms
12,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    vector<mint> fact(H + W + 1), inv(H + W + 1), a(H + 1), b(W + 1);
    fact[0] = 1;
    for(int i = 1; i <= H + W; i++) fact[i] = i * fact[i - 1];
    inv[H + W] = 1 / fact[H + W];
    for(int i = H + W; i >= 1; i--) inv[i - 1] = i * inv[i];

    for(int i = 0; i <= H / 2; i++) a[H - i] = inv[i] * inv[H - 2 * i];
    for(int i = 0; i <= W / 2; i++) b[W - i] = inv[i] * inv[W - 2 * i];

    auto c = convolution(a, b);

    mint ans;
    for(int i = (H + W) / 2; i <= H + W; i++) ans += fact[i] * c[i];

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