結果

問題 No.1127 変形パスカルの三角形
ユーザー tonegawatonegawa
提出日時 2020-08-18 09:58:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,070 ms / 1,500 ms
コード長 744 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 99,064 KB
最終ジャッジ日時 2024-04-20 05:24:50
合計ジャッジ時間 15,168 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,608 KB
testcase_01 AC 1,070 ms
98,116 KB
testcase_02 AC 508 ms
88,356 KB
testcase_03 AC 347 ms
86,272 KB
testcase_04 AC 93 ms
77,956 KB
testcase_05 AC 301 ms
84,336 KB
testcase_06 AC 970 ms
99,064 KB
testcase_07 AC 179 ms
81,412 KB
testcase_08 AC 163 ms
80,864 KB
testcase_09 AC 734 ms
93,704 KB
testcase_10 AC 712 ms
95,200 KB
testcase_11 AC 546 ms
90,196 KB
testcase_12 AC 482 ms
88,116 KB
testcase_13 AC 402 ms
88,440 KB
testcase_14 AC 322 ms
85,132 KB
testcase_15 AC 149 ms
80,384 KB
testcase_16 AC 360 ms
85,732 KB
testcase_17 AC 164 ms
81,348 KB
testcase_18 AC 388 ms
86,256 KB
testcase_19 AC 536 ms
89,552 KB
testcase_20 AC 610 ms
91,568 KB
testcase_21 AC 597 ms
92,112 KB
testcase_22 AC 170 ms
80,936 KB
testcase_23 AC 734 ms
95,056 KB
testcase_24 AC 375 ms
86,928 KB
testcase_25 AC 408 ms
87,076 KB
testcase_26 AC 475 ms
88,960 KB
testcase_27 AC 537 ms
88,460 KB
testcase_28 AC 556 ms
90,308 KB
testcase_29 AC 156 ms
81,192 KB
testcase_30 AC 115 ms
78,888 KB
testcase_31 AC 625 ms
92,112 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