結果
問題 | No.1474 かさまJ |
ユーザー | tamato |
提出日時 | 2021-04-09 22:27:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,796 ms / 2,500 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 462 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 284,532 KB |
最終ジャッジ日時 | 2024-06-25 06:03:35 |
合計ジャッジ時間 | 10,975 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
63,488 KB |
testcase_01 | AC | 59 ms
63,488 KB |
testcase_02 | AC | 76 ms
72,320 KB |
testcase_03 | AC | 59 ms
63,488 KB |
testcase_04 | AC | 57 ms
63,744 KB |
testcase_05 | AC | 705 ms
198,268 KB |
testcase_06 | AC | 200 ms
90,368 KB |
testcase_07 | AC | 68 ms
68,992 KB |
testcase_08 | AC | 72 ms
71,296 KB |
testcase_09 | AC | 1,057 ms
284,532 KB |
testcase_10 | AC | 106 ms
82,304 KB |
testcase_11 | AC | 69 ms
69,120 KB |
testcase_12 | AC | 70 ms
70,784 KB |
testcase_13 | AC | 1,192 ms
260,012 KB |
testcase_14 | AC | 373 ms
118,656 KB |
testcase_15 | AC | 225 ms
88,704 KB |
testcase_16 | AC | 105 ms
86,528 KB |
testcase_17 | AC | 452 ms
132,864 KB |
testcase_18 | AC | 1,485 ms
260,096 KB |
testcase_19 | AC | 1,707 ms
261,120 KB |
testcase_20 | AC | 1,796 ms
261,120 KB |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline # comb init nmax = 2 * 10 ** 5 + 10 # change here fac = [0] * nmax finv = [0] * nmax inv = [0] * nmax fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, nmax): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod def comb(n, r): if n < r: return 0 else: return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod N, MP, MQ, L = map(int, input().split()) S = list(map(int, input().split())) dp = [[0] * (MQ+1) for _ in range(N+1)] dp[0][0] = 1 for s in S: dp_new = [[0] * (MQ+1) for _ in range(N+1)] cs = [[0] * (MQ+2) for _ in range(N+1)] for n in range(N+1): for j in range(MQ+1): cs[n][j+1] = (cs[n][j] + dp[n][j])%mod for n in range(N+1): for j in range(MQ+1): # use q if n: dp_new[n][j] = (dp_new[n][j] + (cs[n-1][j] - cs[n-1][max(0, j - s)])%mod)%mod # don't use q dp_new[n][j] = (dp_new[n][j] + dp[n][j])%mod dp = dp_new ans = 0 for n in range(N+1): for j in range(MQ+1): p_need = n * L - j if p_need <= MP: ans = (ans + (comb(MP - p_need + N-1, N-1) * dp[n][j])%mod)%mod print(ans) if __name__ == '__main__': main()