結果
問題 |
No.2802 Pill Bug in Grid Maze
|
ユーザー |
👑 |
提出日時 | 2023-10-23 23:51:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 196 ms / 2,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 2,283 ms |
コンパイル使用メモリ | 197,444 KB |
最終ジャッジ日時 | 2025-02-17 13:20:03 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <atcoder/modint> #include <bits/stdc++.h> #define ll long long using namespace std; using namespace atcoder; using mint = modint998244353; mint comb(int n, int r, vector<mint> &facts) { return facts.at(n) / (facts.at(r) * facts.at(n-r)); } int main() { ll H, W; cin >> H >> W; if (H == 1 || W == 1) { cout << 1 << endl; return 0; } vector<mint> facts(max(H, W+1), 1); for (int i = 0; i < facts.size() - 1; i++) { facts.at(i+1) = (i+1) * facts.at(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, facts) * comb(W-1, y, facts); } cout << ans.val() << endl; }