結果

問題 No.797 Noelちゃんとピラミッド
ユーザー MayimgMayimg
提出日時 2019-03-16 06:19:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 199,648 KB
実行使用メモリ 6,520 KB
最終ジャッジ日時 2023-09-14 15:05:50
合計ジャッジ時間 4,995 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,284 KB
testcase_01 AC 5 ms
6,264 KB
testcase_02 AC 5 ms
6,432 KB
testcase_03 AC 18 ms
6,288 KB
testcase_04 AC 18 ms
6,312 KB
testcase_05 AC 18 ms
6,520 KB
testcase_06 AC 18 ms
6,188 KB
testcase_07 AC 18 ms
6,316 KB
testcase_08 AC 18 ms
6,288 KB
testcase_09 AC 18 ms
6,288 KB
testcase_10 AC 18 ms
6,288 KB
testcase_11 AC 17 ms
6,188 KB
testcase_12 AC 18 ms
6,312 KB
testcase_13 AC 18 ms
6,184 KB
testcase_14 AC 17 ms
6,336 KB
testcase_15 AC 18 ms
6,276 KB
testcase_16 AC 18 ms
6,196 KB
testcase_17 AC 18 ms
6,364 KB
testcase_18 AC 18 ms
6,212 KB
testcase_19 AC 18 ms
6,260 KB
testcase_20 AC 18 ms
6,316 KB
testcase_21 AC 18 ms
6,256 KB
testcase_22 AC 17 ms
6,300 KB
testcase_23 AC 14 ms
6,276 KB
testcase_24 AC 8 ms
6,316 KB
testcase_25 AC 13 ms
6,268 KB
testcase_26 AC 13 ms
6,244 KB
testcase_27 AC 18 ms
6,188 KB
testcase_28 AC 17 ms
6,296 KB
testcase_29 AC 7 ms
6,504 KB
testcase_30 AC 9 ms
6,184 KB
testcase_31 AC 15 ms
6,264 KB
testcase_32 AC 9 ms
6,340 KB
testcase_33 AC 12 ms
6,436 KB
testcase_34 AC 10 ms
6,428 KB
testcase_35 AC 18 ms
6,260 KB
testcase_36 AC 7 ms
6,300 KB
testcase_37 AC 17 ms
6,196 KB
testcase_38 AC 16 ms
6,184 KB
testcase_39 AC 12 ms
6,208 KB
testcase_40 AC 7 ms
6,464 KB
testcase_41 AC 7 ms
6,296 KB
testcase_42 AC 13 ms
6,192 KB
testcase_43 AC 5 ms
6,192 KB
testcase_44 AC 5 ms
6,288 KB
testcase_45 AC 5 ms
6,292 KB
testcase_46 AC 5 ms
6,208 KB
testcase_47 AC 5 ms
6,292 KB
testcase_48 AC 5 ms
6,188 KB
testcase_49 AC 5 ms
6,272 KB
testcase_50 AC 5 ms
6,244 KB
testcase_51 AC 5 ms
6,188 KB
testcase_52 AC 5 ms
6,196 KB
testcase_53 AC 5 ms
6,432 KB
testcase_54 AC 5 ms
6,432 KB
testcase_55 AC 5 ms
6,192 KB
testcase_56 AC 5 ms
6,336 KB
testcase_57 AC 6 ms
6,432 KB
testcase_58 AC 5 ms
6,284 KB
testcase_59 AC 6 ms
6,508 KB
testcase_60 AC 5 ms
6,192 KB
testcase_61 AC 6 ms
6,276 KB
testcase_62 AC 6 ms
6,288 KB
権限があれば一括ダウンロードができます

ソースコード

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