結果
問題 |
No.1127 変形パスカルの三角形
|
ユーザー |
![]() |
提出日時 | 2023-01-02 02:10:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 336 ms / 1,500 ms |
コード長 | 646 bytes |
コンパイル時間 | 519 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 85,888 KB |
最終ジャッジ日時 | 2024-11-27 00:32:11 |
合計ジャッジ時間 | 8,079 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
a, b = map(int, input().split()) N, K = map(int, input().split()) mod = 10 ** 9 + 7 n = 505050 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 ans = comb(N - 1, K - 1) * a + comb(N - 1, K - 2) * b print(ans%mod) ans = a**2 + b**2 for i in range(1, N): ans += (comb(N - 1, i) * a + comb(N - 1, i - 1) * b)**2 ans %= mod print(ans)