結果

問題 No.797 Noelちゃんとピラミッド
ユーザー Mayimg
提出日時 2019-03-16 06:19:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 192,560 KB
最終ジャッジ日時 2025-01-06 22:28:50
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 123456;

long long fac[MAX], finv[MAX], inv[MAX];

inline void add(long long &x, long long y) {
  x += y;
  if(x >= mod) x -= mod;
}

inline void sub(long long &x, long long y) {
  x -= y;
  if(x < 0) x += mod;
}

inline long long mul(long long x, long long y) {
  return x % mod * y % mod;
}

inline long long inverse(long long x) {
  x = (x % mod + mod) % mod;
  long long y = mod, u = 1, v = 0;
  while(y) {
    long long t = x / y;
    x -= t * y; swap(x, y);
    u -= t * v; swap(u, v);
  }
  return (u % mod + mod) % mod;
}

inline long long power(long long x, long long y) {
  long long res = 1;
  while(y) {
    if(y & 1) res = mul(res, x);
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}

inline void pre_mod_nCk() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = mod - mul(inv[mod % i], mod / i);
    finv[i] = mul(finv[i - 1], inv[i]);
  }
}

inline long long nCk(int n, int k) {
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return mul(fac[n], mul(finv[k], finv[n - k]));
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  pre_mod_nCk();
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    add(ans, mul(x, nCk(n - 1, i - 1)));
  }
  cout << ans << endl;
  return 0;	
}
0