結果

問題 No.1127 変形パスカルの三角形
ユーザー karinohitokarinohito
提出日時 2021-07-26 01:11:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 1,500 ms
コード長 1,334 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 172,764 KB
実行使用メモリ 16,080 KB
最終ジャッジ日時 2023-09-28 15:03:50
合計ジャッジ時間 4,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 63 ms
14,784 KB
testcase_02 AC 51 ms
12,608 KB
testcase_03 AC 31 ms
8,408 KB
testcase_04 AC 9 ms
4,716 KB
testcase_05 AC 32 ms
9,040 KB
testcase_06 AC 70 ms
16,080 KB
testcase_07 AC 19 ms
6,832 KB
testcase_08 AC 16 ms
5,736 KB
testcase_09 AC 51 ms
12,456 KB
testcase_10 AC 50 ms
11,620 KB
testcase_11 AC 43 ms
10,528 KB
testcase_12 AC 44 ms
11,632 KB
testcase_13 AC 43 ms
11,512 KB
testcase_14 AC 34 ms
9,460 KB
testcase_15 AC 18 ms
6,548 KB
testcase_16 AC 31 ms
8,264 KB
testcase_17 AC 18 ms
6,548 KB
testcase_18 AC 33 ms
8,552 KB
testcase_19 AC 50 ms
12,416 KB
testcase_20 AC 48 ms
11,612 KB
testcase_21 AC 52 ms
13,172 KB
testcase_22 AC 16 ms
5,884 KB
testcase_23 AC 50 ms
11,800 KB
testcase_24 AC 32 ms
8,836 KB
testcase_25 AC 38 ms
9,912 KB
testcase_26 AC 38 ms
9,888 KB
testcase_27 AC 40 ms
10,100 KB
testcase_28 AC 42 ms
10,576 KB
testcase_29 AC 16 ms
6,088 KB
testcase_30 AC 12 ms
5,080 KB
testcase_31 AC 47 ms
11,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;
Graph G;
vll dist;
vector<bool> seen;
set<pair<ll, ll>> S;

ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	if (n < k) return 0;
	return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}

int main() {
	ll A,B,N,K;
	cin>>A>>B>>N>>K;
	A%=mod;
	B%=mod;
	prenCkModp(2*N+K);
	ll AA=(A%mod)*nCk(N-1,K-1);
	ll BB=(B%mod)*nCk(N-1,N-K+1);
	cout<<(AA%mod+BB%mod)%mod<<endl;
	ll an=A*A+B*B;
	an%=mod;
	for(ll k=2;k<=N;k++){
		AA=(A%mod)*nCk(N-1,k-1);
		BB=(B%mod)*nCk(N-1,N-k+1);
		AA%=mod;
		BB%=mod;
		an+=((AA+BB)*(AA+BB))%mod;
		
	}
	cout<<an%mod<<endl;

}
0