結果
| 問題 |
No.1127 変形パスカルの三角形
|
| ユーザー |
|
| 提出日時 | 2022-08-27 14:21:59 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 1,500 ms |
| コード長 | 1,152 bytes |
| コンパイル時間 | 1,571 ms |
| コンパイル使用メモリ | 147,944 KB |
| 実行使用メモリ | 6,784 KB |
| 最終ジャッジ日時 | 2024-10-14 12:15:08 |
| 合計ジャッジ時間 | 4,467 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
#include<complex>
#include<fstream>
#include<cstdlib>
#include<functional>
#include<array>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
ll fact[200001],invfac[200001];
ll mypow(int x,ll n){
if(n==0)
return 1;
if(n%2==1)
return mypow(x,n-1)*x%mod;
ll res=mypow(x,n/2);
return res*res%mod;
}
ll inv(int x){
return mypow(x,mod-2);
}
ll comb(int n,int r){
if(!(0<=r&&r<=n))
return 0;
return fact[n]*invfac[r]%mod*invfac[n-r]%mod;
}
int main(){
fact[0]=1;
for(int i=1;i<=200000;i++)
fact[i]=i*fact[i-1]%mod;
for(int i=0;i<=200000;i++)
invfac[i]=inv(fact[i]);
ll n,k,a,b;
cin>>a>>b>>n>>k;
a%=mod,b%=mod;
cout<<(a*comb(n-1,k-1)+b*comb(n-1,k-2))%mod<<endl;
int sum=0;
for(int k=1;k<=n+1;k++){
int tmp=(a*comb(n-1,k-1)+b*comb(n-1,k-2))%mod;
sum=(sum+(ll)tmp*tmp)%mod;
}
cout<<sum<<endl;
}