結果
問題 | No.1693 Invasion |
ユーザー | O2MT |
提出日時 | 2021-10-01 23:11:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 360 ms / 2,000 ms |
コード長 | 2,613 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 94,480 KB |
最終ジャッジ日時 | 2024-07-19 15:55:53 |
合計ジャッジ時間 | 4,370 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,608 KB |
testcase_01 | AC | 43 ms
52,608 KB |
testcase_02 | AC | 45 ms
59,008 KB |
testcase_03 | AC | 47 ms
60,288 KB |
testcase_04 | AC | 40 ms
52,736 KB |
testcase_05 | AC | 51 ms
62,464 KB |
testcase_06 | AC | 53 ms
62,976 KB |
testcase_07 | AC | 53 ms
63,360 KB |
testcase_08 | AC | 52 ms
62,464 KB |
testcase_09 | AC | 237 ms
88,148 KB |
testcase_10 | AC | 195 ms
92,032 KB |
testcase_11 | AC | 122 ms
82,816 KB |
testcase_12 | AC | 215 ms
92,928 KB |
testcase_13 | AC | 140 ms
81,664 KB |
testcase_14 | AC | 146 ms
82,176 KB |
testcase_15 | AC | 113 ms
79,232 KB |
testcase_16 | AC | 164 ms
82,688 KB |
testcase_17 | AC | 39 ms
52,992 KB |
testcase_18 | AC | 310 ms
94,480 KB |
testcase_19 | AC | 122 ms
91,116 KB |
testcase_20 | AC | 48 ms
60,800 KB |
testcase_21 | AC | 335 ms
93,848 KB |
testcase_22 | AC | 329 ms
94,080 KB |
testcase_23 | AC | 360 ms
94,336 KB |
ソースコード
class Factorial(): def __init__(self, mod=998244353): self.mod = mod self._factorial = [1] self._size = 1 self._factorial_inv = [1] self._size_inv = 1 def __call__(self, n): '''n! % mod ''' return self.fact(n) def fact(self, n): '''n! % mod ''' if n >= self.mod: return 0 self.make(n) return self._factorial[n] def fact_inv(self, n): '''n!^-1 % mod ''' if n >= self.mod: raise ValueError('Modinv is not exist! arg={}'.format(n)) self.make_inv(n) return self._factorial_inv[n] def comb(self, n, r): ''' nCr % mod ''' if r > n: return 0 t = self.fact_inv(n-r)*self.fact_inv(r) % self.mod return self(n)*t % self.mod def comb_with_repetition(self, n, r): ''' nHr % mod ''' t = self.fact_inv(n-1)*self.fact_inv(r) % self.mod return self(n+r-1)*t % self.mod def perm(self, n, r): ''' nPr % mod ''' if r > n: return 0 return self(n)*self.fact_inv(n-r) % self.mod @staticmethod def xgcd(a, b): ''' return (g, x, y) such that a*x + b*y = g = gcd(a, b) ''' x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: (q, a), b = divmod(b, a), a y0, y1 = y1, y0 - q * y1 x0, x1 = x1, x0 - q * x1 return b, x0, y0 def modinv(self, n): g, x, _ = self.xgcd(n, self.mod) if g != 1: raise ValueError('Modinv is not exist! arg={}'.format(n)) return x % self.mod def make(self, n): if n >= self.mod: n = self.mod if self._size < n+1: for i in range(self._size, n+1): self._factorial.append(self._factorial[i-1]*i % self.mod) self._size = n+1 def make_inv(self, n): if n >= self.mod: n = self.mod self.make(n) if self._size_inv < n+1: for i in range(self._size_inv, n+1): self._factorial_inv.append(self.modinv(self._factorial[i])) self._size_inv = n+1 N,M = map(int,input().split()) A = list(map(int,input().split())) dp = [[False,M] for _ in range(M+1)] dp[0] = [True,0] f = Factorial() for i in range(N): for j in range(M-A[i]+1): if dp[j][0]: dp[j+A[i]][0] = True dp[j+A[i]][1] = min(dp[j+A[i]][1],dp[j][1]+1) ans = 1 for i in range(1,M+1): if dp[i][0]: ans += f.comb(M-dp[i][1],i-dp[i][1]) ans %= 998244353 print(ans)