結果

問題 No.797 Noelちゃんとピラミッド
ユーザー ceni1055ceni1055
提出日時 2019-03-15 21:59:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 664 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 170,644 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-07-01 20:57:29
合計ジャッジ時間 24,950 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <assert.h>

using namespace std;

const int MOD = 1e9 + 7;

vector<long long> fac(300001), ifac(300001);

long long mpow(long long x, long long n)
{
  long long ans = 1;
  while (n != 0)
  {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}

long long comb(long long a, long long b)
{
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  long long tmp = ifac[a - b] * ifac[b] % MOD;
  return tmp * fac[a] % MOD;
}

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  fac[0] = 1;
  ifac[0] = 1;
  for (long long i = 0; i < 300000; i++)
  {
    fac[i + 1] = fac[i] * (i + 1) % MOD;
    ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++)
  {
    ans = (ans + comb(N - 1, i) * a[i]) % MOD;
    cerr << i << " " << comb(N - 1, i) << endl;
  }
  cout << ans << endl;

  return 0;
}
0