結果

問題 No.1693 Invasion
ユーザー 👑 tamatotamato
提出日時 2021-10-01 21:38:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 79,756 KB
最終ジャッジ日時 2023-09-26 16:42:24
合計ジャッジ時間 4,276 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
78,616 KB
testcase_01 AC 85 ms
78,440 KB
testcase_02 AC 84 ms
78,428 KB
testcase_03 AC 88 ms
78,428 KB
testcase_04 AC 81 ms
78,300 KB
testcase_05 AC 86 ms
78,608 KB
testcase_06 AC 86 ms
78,592 KB
testcase_07 AC 88 ms
78,700 KB
testcase_08 AC 88 ms
78,520 KB
testcase_09 AC 149 ms
79,252 KB
testcase_10 AC 118 ms
79,476 KB
testcase_11 AC 100 ms
79,132 KB
testcase_12 AC 126 ms
79,512 KB
testcase_13 AC 109 ms
78,884 KB
testcase_14 AC 113 ms
79,036 KB
testcase_15 AC 107 ms
78,880 KB
testcase_16 AC 132 ms
79,152 KB
testcase_17 AC 84 ms
78,752 KB
testcase_18 AC 173 ms
79,492 KB
testcase_19 AC 91 ms
79,480 KB
testcase_20 AC 89 ms
78,600 KB
testcase_21 AC 166 ms
79,404 KB
testcase_22 AC 172 ms
79,560 KB
testcase_23 AC 169 ms
79,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
eps = 10**-9
inf = 10 ** 9


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

    # comb init
    nmax = 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 = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [inf] * (M+1)
    dp[0] = 0
    for i in range(M):
        for a in A:
            if i + a <= M:
                dp[i+a] = min(dp[i+a], dp[i] + 1)

    ans = 0
    for i in range(M+1):
        if dp[i] != inf:
            ans = (ans + comb(M - dp[i], i - dp[i]))%mod
    print(ans)


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