結果

問題 No.1127 変形パスカルの三角形
ユーザー kozykozy
提出日時 2020-07-22 11:17:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 764 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 24,652 KB
最終ジャッジ日時 2023-09-02 00:42:37
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,904 KB
testcase_01 TLE -
testcase_02 AC 1,161 ms
19,236 KB
testcase_03 AC 781 ms
16,220 KB
testcase_04 AC 133 ms
10,404 KB
testcase_05 AC 679 ms
15,412 KB
testcase_06 TLE -
testcase_07 AC 383 ms
13,128 KB
testcase_08 AC 338 ms
12,992 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 AC 1,301 ms
19,616 KB
testcase_12 AC 1,173 ms
18,772 KB
testcase_13 AC 939 ms
17,816 KB
testcase_14 AC 752 ms
16,584 KB
testcase_15 AC 295 ms
12,880 KB
testcase_16 AC 849 ms
16,736 KB
testcase_17 AC 352 ms
12,792 KB
testcase_18 AC 934 ms
17,584 KB
testcase_19 AC 1,300 ms
19,496 KB
testcase_20 AC 1,483 ms
20,336 KB
testcase_21 AC 1,312 ms
20,000 KB
testcase_22 AC 328 ms
13,216 KB
testcase_23 TLE -
testcase_24 AC 826 ms
16,372 KB
testcase_25 AC 860 ms
17,260 KB
testcase_26 AC 1,070 ms
18,492 KB
testcase_27 AC 1,214 ms
19,360 KB
testcase_28 AC 1,328 ms
19,356 KB
testcase_29 AC 310 ms
12,880 KB
testcase_30 AC 198 ms
11,832 KB
testcase_31 AC 1,476 ms
20,472 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 answer(s,p):
  return (b*cmb(s-1,p-2)%mod+a*cmb(s-1,p-1)%mod)%mod
print(answer(n,k))
print((a*answer(2*n-1,n)%mod+b*answer(2*n-1,n+1)%mod)%mod)
0