結果

問題 No.1127 変形パスカルの三角形
ユーザー a01sa01to
提出日時 2025-11-13 01:16:30
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 1,500 ms
コード長 926 bytes
コンパイル時間 3,126 ms
コンパイル使用メモリ 281,788 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-13 01:16:35
合計ジャッジ時間 4,809 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

#include <atcoder/modint>
using mint = atcoder::modint1000000007;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  ll a, b, n, k;
  cin >> a >> b >> n >> k;
  vector<mint> fact(n + 1, 1);
  rep(i, n) fact[i + 1] = fact[i] * (i + 1);
  vector<mint> invfact(n + 1);
  invfact[n] = fact[n].inv();
  for (int i = n; i > 0; --i) invfact[i - 1] = invfact[i] * i;
  auto Combi = [&](int n, int r) {
    return fact[n] * invfact[r] * invfact[n - r];
  };
  mint ans1 = Combi(n - 1, k - 1) * a + Combi(n - 1, n - k + 1) * b;
  mint ans2 = mint(a).pow(2) + mint(b).pow(2);
  for (int i = 1; i < n; ++i) {
    mint num = Combi(n - 1, i - 1) * a + Combi(n - 1, n - 1 - i) * b;
    ans2 += num * num;
  }
  cout << ans1.val() << '\n';
  cout << ans2.val() << '\n';
  return 0;
}
0