結果

問題 No.2303 Frog on Grid
ユーザー pockynypockyny
提出日時 2023-05-13 11:54:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 116,448 KB
実行使用メモリ 14,384 KB
最終ジャッジ日時 2023-08-19 12:36:18
合計ジャッジ時間 4,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,120 KB
testcase_01 AC 15 ms
8,140 KB
testcase_02 AC 53 ms
13,652 KB
testcase_03 AC 33 ms
10,484 KB
testcase_04 AC 54 ms
13,520 KB
testcase_05 AC 54 ms
13,704 KB
testcase_06 AC 33 ms
10,508 KB
testcase_07 AC 53 ms
13,384 KB
testcase_08 AC 54 ms
13,676 KB
testcase_09 AC 23 ms
9,124 KB
testcase_10 AC 33 ms
10,592 KB
testcase_11 AC 24 ms
8,956 KB
testcase_12 AC 34 ms
10,716 KB
testcase_13 AC 15 ms
8,112 KB
testcase_14 AC 15 ms
8,188 KB
testcase_15 AC 15 ms
8,124 KB
testcase_16 AC 15 ms
8,064 KB
testcase_17 AC 15 ms
8,068 KB
testcase_18 AC 55 ms
14,248 KB
testcase_19 AC 55 ms
14,056 KB
testcase_20 AC 54 ms
14,248 KB
testcase_21 AC 55 ms
14,256 KB
testcase_22 AC 55 ms
14,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
const int MX = 400010;
mint f[MX],inv[MX],fi[MX];
constexpr ll mod = 998244353;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i];
    }
    f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i;
        fi[i] = fi[i-1]*inv[i];
    }
}

mint nck(ll n, ll k){
    if(n<0 || k<0 || n<k) return 0;
    return f[n]*fi[k]*fi[n-k];
}

int main(){
    solve();
    ll i,h,w; cin >> h >> w;
    vector<mint> ff(h + 1),gg(w + 1);
    for(i=(h + 1)/2;i<=h;i++){
        ff[i] = fi[h - i]*fi[2*i - h];
    }
    for(i=(w + 1)/2;i<=w;i++){
        gg[i] = fi[w - i]*fi[2*i - w];
    }
    vector<mint> hh = convolution(ff,gg);
    mint ans = 0;
    for(i=0;i<=(h + w);i++){
        ans += hh[i]*f[i];
    }
    cout << ans.val() << "\n";
}
0