結果

問題 No.1127 変形パスカルの三角形
ユーザー kotatsugame
提出日時 2020-07-27 00:56:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 1,500 ms
コード長 643 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 65,664 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-06-28 19:45:59
合計ジャッジ時間 1,581 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
const long mod=1e9+7;
long N,K,A,B;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long fac[2<<17],inv[2<<17];
main()
{
	cin>>A>>B>>N>>K;
	A%=mod;
	B%=mod;
	fac[0]=1;
	for(int i=1;i<=N;i++)fac[i]=fac[i-1]*i%mod;
	inv[N]=power(fac[N],mod-2);
	for(int i=N;i--;)inv[i]=inv[i+1]*(i+1)%mod;
	cout<<(A*fac[N-1]%mod*inv[K-1]%mod*inv[N-K]%mod+B*fac[N-1]%mod*inv[K-2]%mod*inv[N-K+1]%mod)%mod<<endl;
	long ans=0;
	for(int k=1;k<=N+1;k++)
	{
		long T=A*fac[N-1]%mod*inv[k-1]%mod*inv[N-k]%mod+B*fac[N-1]%mod*inv[k-2]%mod*inv[N-k+1]%mod;
		T%=mod;
		ans+=T*T%mod;
	}
	cout<<ans%mod<<endl;
}
0