結果

問題 No.2023 Tiling is Fun
ユーザー hahho28hahho28
提出日時 2022-07-15 17:41:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 78,780 KB
最終ジャッジ日時 2023-09-26 17:45:01
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,200 KB
testcase_01 AC 85 ms
77,412 KB
testcase_02 AC 87 ms
76,692 KB
testcase_03 AC 85 ms
76,692 KB
testcase_04 AC 79 ms
75,572 KB
testcase_05 AC 83 ms
76,480 KB
testcase_06 AC 84 ms
76,720 KB
testcase_07 AC 87 ms
77,772 KB
testcase_08 AC 84 ms
77,104 KB
testcase_09 AC 89 ms
77,692 KB
testcase_10 AC 88 ms
77,604 KB
testcase_11 AC 73 ms
71,324 KB
testcase_12 AC 72 ms
71,204 KB
testcase_13 AC 73 ms
71,072 KB
testcase_14 AC 81 ms
77,104 KB
testcase_15 AC 86 ms
76,984 KB
testcase_16 AC 83 ms
77,296 KB
testcase_17 AC 91 ms
78,780 KB
testcase_18 AC 90 ms
78,740 KB
testcase_19 AC 84 ms
77,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def modinv(x: int, mod: int) -> int:
    """
    Z/(mod Z)上でのxの逆元

    :param x: 整数
    :param mod: 整数
    :return: x * y % mod = 1を満たすy
    """
    s, ps, r, pr = 0, 1, mod, x
    while r != 0:
        pr, (q, r) = r, divmod(pr, r)
        ps, s = s, ps - q * s
    if pr == 1:
        return ps if ps >= 0 else ps + mod
    raise ValueError("base is not invertible for the given modulus")


def factorials_with_inv(k, mod):
    """
    0! ... k! とそれらのmod逆元を求めて返す
    """
    fac = [1] * (k + 1)
    inv = [1] * (k + 1)
    t = 1
    for i in range(1, k + 1):
        t = (t * i) % mod
        fac[i] = t
    t = modinv(t, mod)
    for i in reversed(range(1, k + 1)):
        inv[i] = t
        t = (t * i) % mod
    return fac, inv


mod = 998244353

a, b = map(int, input().split())
a -= 1
b -= 1
fac, inv = factorials_with_inv(a+b, mod)

print(fac[a+b]*inv[b]%mod*inv[a]%mod)
0