結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー tamatotamato
提出日時 2020-08-24 22:36:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 894 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 78,720 KB
最終ジャッジ日時 2024-04-24 03:57:02
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
70,016 KB
testcase_01 AC 88 ms
74,368 KB
testcase_02 AC 87 ms
71,680 KB
testcase_03 AC 83 ms
71,296 KB
testcase_04 AC 88 ms
74,112 KB
testcase_05 AC 82 ms
70,528 KB
testcase_06 AC 94 ms
78,720 KB
testcase_07 AC 81 ms
72,192 KB
testcase_08 AC 80 ms
71,936 KB
testcase_09 AC 76 ms
72,192 KB
testcase_10 AC 72 ms
67,840 KB
testcase_11 AC 72 ms
67,840 KB
testcase_12 AC 89 ms
74,240 KB
testcase_13 AC 90 ms
75,776 KB
testcase_14 AC 91 ms
77,056 KB
testcase_15 AC 70 ms
68,096 KB
testcase_16 AC 71 ms
67,968 KB
testcase_17 AC 72 ms
67,968 KB
testcase_18 AC 69 ms
67,712 KB
testcase_19 AC 71 ms
68,096 KB
testcase_20 AC 70 ms
67,456 KB
testcase_21 AC 66 ms
67,968 KB
testcase_22 AC 76 ms
69,888 KB
testcase_23 AC 70 ms
67,968 KB
testcase_24 AC 69 ms
67,712 KB
testcase_25 AC 69 ms
67,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    nmax = 4 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    N, M, A, B = map(int, input().split())
    ans = 0
    for i in range(1, M+1):
        C = min(B+i, M)
        if C - (i + (N-1) * A) < 0:
            break
        ans = (ans + comb(C - (i + (N-1) * A) + N-1, N-1))%mod
    print((ans * fac[N])%mod)


if __name__ == '__main__':
    main()
0