結果

問題 No.1127 変形パスカルの三角形
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2020-07-23 16:31:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,267 ms / 1,500 ms
コード長 745 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 99,764 KB
最終ジャッジ日時 2023-09-05 22:24:44
合計ジャッジ時間 19,031 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,820 KB
testcase_01 AC 1,267 ms
99,112 KB
testcase_02 AC 616 ms
89,440 KB
testcase_03 AC 427 ms
86,812 KB
testcase_04 AC 128 ms
78,972 KB
testcase_05 AC 370 ms
85,348 KB
testcase_06 AC 1,208 ms
99,764 KB
testcase_07 AC 228 ms
82,748 KB
testcase_08 AC 208 ms
81,660 KB
testcase_09 AC 914 ms
94,080 KB
testcase_10 AC 902 ms
95,556 KB
testcase_11 AC 689 ms
91,028 KB
testcase_12 AC 611 ms
89,156 KB
testcase_13 AC 510 ms
89,516 KB
testcase_14 AC 410 ms
86,228 KB
testcase_15 AC 198 ms
81,156 KB
testcase_16 AC 448 ms
86,756 KB
testcase_17 AC 211 ms
82,348 KB
testcase_18 AC 488 ms
87,380 KB
testcase_19 AC 667 ms
90,624 KB
testcase_20 AC 749 ms
92,444 KB
testcase_21 AC 732 ms
93,136 KB
testcase_22 AC 212 ms
81,780 KB
testcase_23 AC 895 ms
95,660 KB
testcase_24 AC 459 ms
87,992 KB
testcase_25 AC 486 ms
88,276 KB
testcase_26 AC 578 ms
89,800 KB
testcase_27 AC 656 ms
89,676 KB
testcase_28 AC 688 ms
91,304 KB
testcase_29 AC 200 ms
81,732 KB
testcase_30 AC 152 ms
80,540 KB
testcase_31 AC 791 ms
93,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
mod=10**9+7
a,b=map(int,input().split())
n,k=map(int,input().split())
def ans(x,y):
  return (a*cmb(x-1,y-1)+b*cmb(x-1,y-2))%mod
print(ans(n,k))
print((a*ans(2*n-1,n)+b*ans(2*n-1,n+1))%mod)
0