結果

問題 No.1127 変形パスカルの三角形
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-11-21 14:29:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 420 ms / 1,500 ms
コード長 952 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 23,828 KB
最終ジャッジ日時 2023-09-30 21:51:07
合計ジャッジ時間 9,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,904 KB
testcase_01 AC 420 ms
23,828 KB
testcase_02 AC 302 ms
19,088 KB
testcase_03 AC 223 ms
16,164 KB
testcase_04 AC 64 ms
10,156 KB
testcase_05 AC 199 ms
15,404 KB
testcase_06 AC 416 ms
23,824 KB
testcase_07 AC 132 ms
12,688 KB
testcase_08 AC 128 ms
12,420 KB
testcase_09 AC 345 ms
20,932 KB
testcase_10 AC 351 ms
21,180 KB
testcase_11 AC 300 ms
19,072 KB
testcase_12 AC 275 ms
18,368 KB
testcase_13 AC 261 ms
17,448 KB
testcase_14 AC 215 ms
15,696 KB
testcase_15 AC 116 ms
12,032 KB
testcase_16 AC 239 ms
16,656 KB
testcase_17 AC 125 ms
12,292 KB
testcase_18 AC 251 ms
17,224 KB
testcase_19 AC 303 ms
19,080 KB
testcase_20 AC 311 ms
19,740 KB
testcase_21 AC 316 ms
19,796 KB
testcase_22 AC 122 ms
12,268 KB
testcase_23 AC 354 ms
21,212 KB
testcase_24 AC 224 ms
16,288 KB
testcase_25 AC 237 ms
16,744 KB
testcase_26 AC 261 ms
17,616 KB
testcase_27 AC 297 ms
19,160 KB
testcase_28 AC 294 ms
18,852 KB
testcase_29 AC 112 ms
11,980 KB
testcase_30 AC 84 ms
10,716 KB
testcase_31 AC 319 ms
19,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
class counting:
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
        self.fi[-1] = pow(self.fa[-1], mod - 2, mod)
        for i in range(self.n, 0, -1):
            self.fi[i - 1] = self.fi[i] * i % mod
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
    def per(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[n - r] % mod
a, b = map(int, input().split())
n, k = map(int, input().split())
C = counting(n)
print((a * C.comb(n - 1, k - 1) + b * C.comb(n - 1, k - 2)) % mod)
ans = 0
for i in range(n + 1):
    ans += pow(a * C.comb(n - 1, i) + b * C.comb(n - 1, i - 1), 2, mod)
    ans %= mod
print(ans)
0