結果

問題 No.1693 Invasion
ユーザー shotoyooshotoyoo
提出日時 2021-10-01 22:11:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 79,500 KB
最終ジャッジ日時 2023-09-26 17:33:38
合計ジャッジ時間 3,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,340 KB
testcase_01 AC 76 ms
71,444 KB
testcase_02 AC 78 ms
71,288 KB
testcase_03 AC 79 ms
75,660 KB
testcase_04 AC 75 ms
71,232 KB
testcase_05 AC 80 ms
75,796 KB
testcase_06 AC 79 ms
75,764 KB
testcase_07 AC 79 ms
75,508 KB
testcase_08 AC 82 ms
75,948 KB
testcase_09 AC 112 ms
78,436 KB
testcase_10 AC 102 ms
79,384 KB
testcase_11 AC 97 ms
77,612 KB
testcase_12 AC 107 ms
79,276 KB
testcase_13 AC 99 ms
77,296 KB
testcase_14 AC 98 ms
77,404 KB
testcase_15 AC 97 ms
76,708 KB
testcase_16 AC 106 ms
77,392 KB
testcase_17 AC 74 ms
71,268 KB
testcase_18 AC 123 ms
79,500 KB
testcase_19 AC 89 ms
79,300 KB
testcase_20 AC 82 ms
75,496 KB
testcase_21 AC 125 ms
79,264 KB
testcase_22 AC 124 ms
79,356 KB
testcase_23 AC 122 ms
79,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n,m = list(map(int, input().split()))
a = list(map(int, input().split()))
M = 998244353

### 素数の逆元とCombination

N = n+m+10 # 必要なテーブルサイズ
g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M=M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return ((g1[n] * g2[r] % M) * g2[n-r]) % M
def perm(n, r, M=M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M
inf = 10**9
dp = [inf]*(m+1)
dp[0] = 0
for i in range(n):
    v = a[i]
    for j in range(m-v+1):
        dp[j+v] = min(dp[j+v], dp[j]+1)
ans = 0
for l in range(m+1):
    k = dp[l]
    if k==inf:
        continue
    ans += cmb(m-k, l-k)
    ans %= M
#     print(l,k)
print(ans%M)
0