結果

問題 No.1693 Invasion
ユーザー AEnAEn
提出日時 2022-05-26 00:28:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 492 ms / 2,000 ms
コード長 1,065 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 233,204 KB
最終ジャッジ日時 2023-10-20 19:16:48
合計ジャッジ時間 7,028 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
61,072 KB
testcase_01 AC 121 ms
61,072 KB
testcase_02 AC 117 ms
61,072 KB
testcase_03 AC 132 ms
65,684 KB
testcase_04 AC 119 ms
61,076 KB
testcase_05 AC 129 ms
67,752 KB
testcase_06 AC 134 ms
65,684 KB
testcase_07 AC 134 ms
67,780 KB
testcase_08 AC 133 ms
65,696 KB
testcase_09 AC 379 ms
178,848 KB
testcase_10 AC 236 ms
123,992 KB
testcase_11 AC 171 ms
87,804 KB
testcase_12 AC 274 ms
135,660 KB
testcase_13 AC 206 ms
103,388 KB
testcase_14 AC 225 ms
112,004 KB
testcase_15 AC 189 ms
94,756 KB
testcase_16 AC 292 ms
136,236 KB
testcase_17 AC 118 ms
61,076 KB
testcase_18 AC 492 ms
233,204 KB
testcase_19 AC 138 ms
69,092 KB
testcase_20 AC 127 ms
65,672 KB
testcase_21 AC 481 ms
217,264 KB
testcase_22 AC 431 ms
217,900 KB
testcase_23 AC 478 ms
221,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
A = list(map(int, input().split()))

class Ncrs():
    def __init__(self, max_r, mod = 998244353) -> None:
        self.mod = mod
        self.fct, self.inv = [1] * (max_r+2), [1]* (max_r+2)
        for i in range(2, max_r+1):
            self.fct[i] = self.fct[i-1] * i % mod
            self.inv[max_r] = pow(self.fct[max_r], mod-2, mod)
        for i in range(max_r, 0,-1):
            self.inv[i-1] = self.inv[i] * i % mod
    def __call__(self, n, k) -> int:
        return self.nck(n, k)
    def nck(self, n, k) -> int:
        if k > n or n <0 or k <0:
            return 0
        return self.fct[n] * self.inv[k] % self.mod * self.inv[n-k] % self.mod

ncr = Ncrs(10**5)
dp = [[float('inf')]*(M+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(M+1):
        if j < A[i]:
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]]+1)
res = 1
for i in range(1, M+1):
    res += ncr(M-dp[-1][i], i-dp[-1][i])
    res %= 998244353
print(res)
0