結果

問題 No.1127 変形パスカルの三角形
ユーザー takakintakakin
提出日時 2020-07-26 20:45:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 517 ms / 1,500 ms
コード長 599 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 39,720 KB
最終ジャッジ日時 2023-09-11 04:57:42
合計ジャッジ時間 16,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 298 ms
39,716 KB
testcase_01 AC 510 ms
39,648 KB
testcase_02 AC 446 ms
39,516 KB
testcase_03 AC 402 ms
39,664 KB
testcase_04 AC 328 ms
39,500 KB
testcase_05 AC 401 ms
39,640 KB
testcase_06 AC 517 ms
39,476 KB
testcase_07 AC 356 ms
39,568 KB
testcase_08 AC 356 ms
39,620 KB
testcase_09 AC 481 ms
39,544 KB
testcase_10 AC 514 ms
39,640 KB
testcase_11 AC 457 ms
39,708 KB
testcase_12 AC 462 ms
39,488 KB
testcase_13 AC 425 ms
39,656 KB
testcase_14 AC 415 ms
39,540 KB
testcase_15 AC 349 ms
39,520 KB
testcase_16 AC 420 ms
39,516 KB
testcase_17 AC 357 ms
39,544 KB
testcase_18 AC 421 ms
39,572 KB
testcase_19 AC 449 ms
39,684 KB
testcase_20 AC 455 ms
39,720 KB
testcase_21 AC 458 ms
39,504 KB
testcase_22 AC 354 ms
39,664 KB
testcase_23 AC 480 ms
39,572 KB
testcase_24 AC 441 ms
39,512 KB
testcase_25 AC 410 ms
39,488 KB
testcase_26 AC 429 ms
39,684 KB
testcase_27 AC 449 ms
39,656 KB
testcase_28 AC 448 ms
39,532 KB
testcase_29 AC 354 ms
39,504 KB
testcase_30 AC 367 ms
39,720 KB
testcase_31 AC 458 ms
39,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
a,b=map(int,input().split())
n,k=map(int,input().split())
a%=mod
b%=mod
n_max=4*(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

if k==1:
	print(a%mod)
else:
	print((a*comb(n-1,k-1)+b*comb(n-1,k-2))%mod)

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