結果

問題 No.1693 Invasion
ユーザー rlangevinrlangevin
提出日時 2023-10-07 01:13:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 80,080 KB
最終ジャッジ日時 2023-10-07 01:13:11
合計ジャッジ時間 5,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
78,576 KB
testcase_01 AC 97 ms
78,380 KB
testcase_02 AC 98 ms
78,424 KB
testcase_03 AC 103 ms
78,820 KB
testcase_04 AC 98 ms
78,692 KB
testcase_05 AC 112 ms
78,796 KB
testcase_06 AC 102 ms
78,780 KB
testcase_07 AC 105 ms
79,064 KB
testcase_08 AC 102 ms
78,908 KB
testcase_09 AC 187 ms
79,700 KB
testcase_10 AC 131 ms
79,896 KB
testcase_11 AC 122 ms
79,504 KB
testcase_12 AC 135 ms
79,916 KB
testcase_13 AC 121 ms
79,376 KB
testcase_14 AC 158 ms
79,552 KB
testcase_15 AC 128 ms
79,288 KB
testcase_16 AC 164 ms
79,440 KB
testcase_17 AC 98 ms
78,500 KB
testcase_18 AC 214 ms
79,888 KB
testcase_19 AC 102 ms
79,344 KB
testcase_20 AC 99 ms
78,836 KB
testcase_21 AC 227 ms
80,044 KB
testcase_22 AC 185 ms
80,080 KB
testcase_23 AC 233 ms
80,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod = 998244353
n = 10**5+5
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


dist = [-1] * (M + 1)
from collections import *
Q = deque()
Q.append(0)
dist[0] = 0
while Q:
    u = Q.popleft()
    for a in A:
        v = u + a
        if v > M:
            continue
        if dist[v] <= dist[u] + 1 and dist[v] != -1:
            continue
        dist[v] = dist[u] + 1
        Q.append(v)
        
ans = 0
for i in range(M + 1):
    if dist[i] == -1:
        continue
    ans += comb(M - dist[i], i - dist[i])
    ans %= mod
    
print(ans)
0