結果

問題 No.1127 変形パスカルの三角形
ユーザー saksak
提出日時 2020-10-12 02:27:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 1,500 ms
コード長 1,428 bytes
コンパイル時間 2,420 ms
コンパイル使用メモリ 203,020 KB
実行使用メモリ 12,408 KB
最終ジャッジ日時 2023-09-27 23:27:11
合計ジャッジ時間 7,297 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
10,892 KB
testcase_01 AC 154 ms
12,408 KB
testcase_02 AC 106 ms
11,876 KB
testcase_03 AC 81 ms
11,540 KB
testcase_04 AC 28 ms
10,940 KB
testcase_05 AC 75 ms
11,520 KB
testcase_06 AC 156 ms
12,408 KB
testcase_07 AC 54 ms
11,212 KB
testcase_08 AC 51 ms
11,400 KB
testcase_09 AC 123 ms
12,004 KB
testcase_10 AC 124 ms
12,000 KB
testcase_11 AC 108 ms
12,272 KB
testcase_12 AC 98 ms
11,736 KB
testcase_13 AC 94 ms
11,816 KB
testcase_14 AC 77 ms
11,476 KB
testcase_15 AC 45 ms
11,352 KB
testcase_16 AC 88 ms
11,872 KB
testcase_17 AC 49 ms
11,212 KB
testcase_18 AC 91 ms
11,880 KB
testcase_19 AC 108 ms
11,924 KB
testcase_20 AC 111 ms
12,036 KB
testcase_21 AC 114 ms
12,004 KB
testcase_22 AC 47 ms
11,396 KB
testcase_23 AC 126 ms
12,272 KB
testcase_24 AC 82 ms
11,472 KB
testcase_25 AC 89 ms
11,812 KB
testcase_26 AC 94 ms
11,928 KB
testcase_27 AC 108 ms
11,808 KB
testcase_28 AC 109 ms
11,872 KB
testcase_29 AC 46 ms
11,280 KB
testcase_30 AC 34 ms
11,256 KB
testcase_31 AC 111 ms
12,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return n<k||k<0 ? 0 : fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll a, b; cin >> a >> b; a %= MOD; b %= MOD;
  ll n, k; cin >> n >> k; n--; k--;

  c_fac();
  ll nk[n+2]; rep(i,n+2) nk[i] = ( nck(n,i)*a + nck(n,i-1)*b ) % MOD;
  ll sum = 0; rep(i,n+2) sum = (sum+nk[i]*nk[i]) % MOD;
  // debug(nk,nk+(n+2));

  cout << nk[k] << endl;
  cout << sum << endl;
  return 0;
}
0