結果

問題 No.1693 Invasion
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-10-01 22:25:59
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,219 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 142,876 KB
最終ジャッジ日時 2023-09-26 18:16:03
合計ジャッジ時間 12,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,328 KB
testcase_01 AC 82 ms
71,036 KB
testcase_02 AC 83 ms
71,196 KB
testcase_03 AC 89 ms
75,860 KB
testcase_04 AC 79 ms
71,236 KB
testcase_05 AC 92 ms
76,336 KB
testcase_06 AC 88 ms
76,016 KB
testcase_07 AC 90 ms
76,344 KB
testcase_08 AC 83 ms
76,076 KB
testcase_09 AC 818 ms
85,168 KB
testcase_10 AC 934 ms
89,312 KB
testcase_11 AC 598 ms
84,700 KB
testcase_12 AC 677 ms
86,988 KB
testcase_13 AC 270 ms
80,948 KB
testcase_14 AC 246 ms
79,256 KB
testcase_15 AC 189 ms
79,404 KB
testcase_16 AC 1,302 ms
98,792 KB
testcase_17 AC 74 ms
71,096 KB
testcase_18 AC 767 ms
84,140 KB
testcase_19 AC 179 ms
80,028 KB
testcase_20 AC 85 ms
75,980 KB
testcase_21 AC 806 ms
85,212 KB
testcase_22 TLE -
testcase_23 AC 910 ms
88,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
a = list(map(int,input().split()))
inf = 10 ** 5 + 1
dp = [inf] * (m+1)
dp[0] = 0
min_ = 0
max_ = 0
n_dp = [inf] * (m+1)
while True:
    
    flg = False
    p_min = 10**5 + 1
    p_max = 0
    for i in range(min_,max_+1):
        n_dp[i] = min(dp[i],n_dp[i])
        for j in range(n):
            if dp[i] != inf:
                if a[j] + i <= m:
                    if i <= m - j:
                        if n_dp[i + a[j]] > dp[i] + 1:
#                             print(i,j)
                            n_dp[i + a[j]] = dp[i] + 1
                            p_max = max(p_max,i  + a[j])
                            p_min = min(p_min,i  + a[j])
    if dp == n_dp:
        break
    min_,max_ = p_min,p_max
#     print(min_,max_)
    dp = n_dp[::]
ans = 0
n = m
fac_arr = [1] * (n+1)
r_s_fac_arr = [1] * (n+1)
mod = 998244353
for i in range(1,n+1):
    fac_arr[i] = (fac_arr[i-1] % mod) * i % mod
    r_s_fac_arr[i] = (r_s_fac_arr[i-1] % mod) * pow(i,mod-2,mod) % mod 
def nCk_Mod(n,k):
    return fac_arr[n]  % mod *  r_s_fac_arr[k] % mod * r_s_fac_arr[n-k] % mod
ans = 0
for i in range(m+1):
    if dp[i] != inf:
        ans += nCk_Mod(m-dp[i],i-dp[i])
        ans %= mod
print(ans)
0