結果

問題 No.2802 Pill Bug in Grid Maze
ユーザー loop0919loop0919
提出日時 2023-10-24 01:20:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 204,880 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-11 19:31:06
合計ジャッジ時間 3,946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 104 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 7 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 6 ms
6,944 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 39 ms
6,940 KB
testcase_21 AC 31 ms
6,940 KB
testcase_22 AC 28 ms
6,940 KB
testcase_23 AC 40 ms
6,944 KB
testcase_24 AC 52 ms
6,940 KB
testcase_25 AC 35 ms
6,940 KB
testcase_26 AC 31 ms
6,944 KB
testcase_27 AC 30 ms
6,940 KB
testcase_28 AC 41 ms
6,940 KB
testcase_29 AC 62 ms
6,940 KB
testcase_30 AC 35 ms
6,944 KB
testcase_31 AC 92 ms
6,944 KB
testcase_32 AC 44 ms
6,940 KB
testcase_33 AC 28 ms
6,944 KB
testcase_34 AC 46 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/stdc++.h>

#define ll long long

using namespace std;
using namespace atcoder;

using mint = modint998244353;

vector<mint> facts(1, 1);
vector<mint> invFacts(1, 1);

mint comb(int n, int r) {
    return facts[n] * invFacts[r] * invFacts[n-r];
}

int main() {
    ll H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }

    for (int i = 1; i <= max(H-2, W-1); i++) {
        facts.push_back(i * facts[i-1]);
        invFacts.push_back(1 / facts[i]);
    }

    mint ans = 0;

    for (int i = 0; i < min(2*H-2, 2*W-1); i++) {
        int x = i / 2;
        int y = (i+1) / 2;
        mint pow = mint(2).pow((H-1)*(W-1) - i);

        ans += pow * comb(H-2, x) * comb(W-1, y);
    }

    cout << ans.val() << endl;
}
0