結果

問題 No.1127 変形パスカルの三角形
ユーザー trineutrontrineutron
提出日時 2020-07-26 16:29:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 997 ms / 1,500 ms
コード長 477 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 23,972 KB
最終ジャッジ日時 2023-09-11 02:44:56
合計ジャッジ時間 19,133 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,928 KB
testcase_01 AC 997 ms
23,972 KB
testcase_02 AC 686 ms
19,108 KB
testcase_03 AC 510 ms
16,260 KB
testcase_04 AC 133 ms
10,224 KB
testcase_05 AC 461 ms
15,432 KB
testcase_06 AC 986 ms
23,912 KB
testcase_07 AC 297 ms
12,880 KB
testcase_08 AC 284 ms
12,716 KB
testcase_09 AC 804 ms
21,064 KB
testcase_10 AC 823 ms
21,448 KB
testcase_11 AC 688 ms
19,360 KB
testcase_12 AC 649 ms
18,448 KB
testcase_13 AC 596 ms
17,680 KB
testcase_14 AC 490 ms
15,960 KB
testcase_15 AC 259 ms
12,180 KB
testcase_16 AC 546 ms
16,776 KB
testcase_17 AC 276 ms
12,428 KB
testcase_18 AC 588 ms
17,500 KB
testcase_19 AC 700 ms
19,396 KB
testcase_20 AC 725 ms
19,800 KB
testcase_21 AC 735 ms
20,032 KB
testcase_22 AC 266 ms
12,380 KB
testcase_23 AC 821 ms
21,384 KB
testcase_24 AC 514 ms
16,276 KB
testcase_25 AC 544 ms
16,876 KB
testcase_26 AC 602 ms
17,808 KB
testcase_27 AC 697 ms
19,284 KB
testcase_28 AC 686 ms
19,000 KB
testcase_29 AC 248 ms
12,008 KB
testcase_30 AC 177 ms
10,900 KB
testcase_31 AC 727 ms
19,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7
a, b = map(int, input().split())
n, k = map(int, input().split())
f = [1]
for i in range(n):
    f.append(f[i] * (i + 1) % mod)
inv = [pow(f[i], mod - 2, mod) for i in range(n + 1)]

def ncr(n, r):
    if r < 0 or n < r:
        return 0
    return f[n] * inv[r] * inv[n - r] % mod

print((a * ncr(n - 1, k - 1) + b * ncr(n - 1, k - 2)) % mod)
ans = 0
for i in range(n + 1):
    ans += (a * ncr(n - 1, i) + b * ncr(n - 1, i - 1)) ** 2
    ans %= mod
print(ans)
0