結果
| 問題 |
No.2802 Pill Bug in Grid Maze
|
| ユーザー |
👑 |
| 提出日時 | 2023-10-19 21:43:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 585 bytes |
| コンパイル時間 | 205 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 851,968 KB |
| 最終ジャッジ日時 | 2024-07-11 19:30:30 |
| 合計ジャッジ時間 | 4,744 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 2 WA * 1 MLE * 1 -- * 27 |
ソースコード
MOD = 998244353
H, W = map(int, input().split())
# 階乗とその逆元を前計算する.
facts = [1]
inv_facts = [1]
for i in range(1, max(H - 1, W)):
facts.append(facts[i-1] * i)
inv_facts.append(inv_facts[i-1] * pow(i, MOD-2, MOD))
# nCr を計算する.
def comb(n, r):
return facts[n] * inv_facts[n-r] * inv_facts[r] % MOD
if H == 1 or W == 1:
print(1)
exit()
ans = 0
for i in range(min(2*H - 2, 2*W - 2)):
x = i // 2
y = (i + 1) // 2
ans += pow(2, (H - 1) * (W - 1) - i, MOD) * comb(H - 2, x) * comb(W - 1, y) % MOD
ans %= MOD
print(ans)