結果

問題 No.1127 変形パスカルの三角形
ユーザー kk
提出日時 2020-08-20 17:10:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 1,500 ms
コード長 1,168 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 199,272 KB
実行使用メモリ 6,724 KB
最終ジャッジ日時 2023-08-03 17:22:30
合計ジャッジ時間 5,716 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
6,624 KB
testcase_01 AC 40 ms
6,496 KB
testcase_02 AC 39 ms
6,452 KB
testcase_03 AC 38 ms
6,516 KB
testcase_04 AC 38 ms
6,488 KB
testcase_05 AC 38 ms
6,496 KB
testcase_06 AC 40 ms
6,568 KB
testcase_07 AC 37 ms
6,500 KB
testcase_08 AC 38 ms
6,456 KB
testcase_09 AC 40 ms
6,520 KB
testcase_10 AC 39 ms
6,460 KB
testcase_11 AC 39 ms
6,480 KB
testcase_12 AC 39 ms
6,488 KB
testcase_13 AC 38 ms
6,488 KB
testcase_14 AC 38 ms
6,624 KB
testcase_15 AC 37 ms
6,500 KB
testcase_16 AC 38 ms
6,480 KB
testcase_17 AC 37 ms
6,444 KB
testcase_18 AC 38 ms
6,576 KB
testcase_19 AC 39 ms
6,440 KB
testcase_20 AC 40 ms
6,492 KB
testcase_21 AC 39 ms
6,524 KB
testcase_22 AC 38 ms
6,724 KB
testcase_23 AC 39 ms
6,440 KB
testcase_24 AC 38 ms
6,564 KB
testcase_25 AC 39 ms
6,696 KB
testcase_26 AC 39 ms
6,488 KB
testcase_27 AC 39 ms
6,548 KB
testcase_28 AC 39 ms
6,696 KB
testcase_29 AC 38 ms
6,492 KB
testcase_30 AC 37 ms
6,580 KB
testcase_31 AC 39 ms
6,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

const long long MOD = 1e9 + 7;
long long f[200000], r[200000];

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

long long comb(int n, int k) {
  if (0 <= k && k <= n)
    return f[n] * r[k] % MOD * r[n-k] % MOD;
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  r[0] = f[0] = 1;
  for (int i = 1; i < 200000; i++) {
    f[i] = i * f[i-1] % MOD;
    r[i] = modpow(f[i], MOD - 2, MOD);
  }

  int n, k;
  long long a, b;
  cin >> a >> b >> n >> k;
  a %= MOD;
  b %= MOD;
  
  long long val = (a * comb(n-1, k-1) + b * comb(n-1, k-2)) % MOD;
  long long sum = 0;
  for (int k = 1; k <= n+1; k++) {
    long long tmp = (a * comb(n-1, k-1) + b * comb(n-1, k-2)) % MOD;
    sum += tmp * tmp % MOD;
    sum %= MOD;
  }

  cout << val << endl;
  cout << sum << endl;
  
  return 0;
}
0