結果

問題 No.797 Noelちゃんとピラミッド
ユーザー playrollerplayroller
提出日時 2019-03-15 23:27:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 167,436 KB
実行使用メモリ 15,528 KB
最終ジャッジ日時 2023-09-14 14:22:28
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
15,196 KB
testcase_01 AC 18 ms
15,436 KB
testcase_02 AC 18 ms
15,260 KB
testcase_03 AC 29 ms
15,456 KB
testcase_04 AC 29 ms
15,512 KB
testcase_05 AC 29 ms
15,388 KB
testcase_06 AC 29 ms
15,312 KB
testcase_07 AC 29 ms
15,368 KB
testcase_08 AC 29 ms
15,436 KB
testcase_09 AC 29 ms
15,452 KB
testcase_10 AC 29 ms
15,428 KB
testcase_11 AC 30 ms
15,336 KB
testcase_12 AC 29 ms
15,384 KB
testcase_13 AC 29 ms
15,328 KB
testcase_14 AC 30 ms
15,388 KB
testcase_15 AC 29 ms
15,444 KB
testcase_16 AC 29 ms
15,372 KB
testcase_17 AC 29 ms
15,432 KB
testcase_18 AC 30 ms
15,380 KB
testcase_19 AC 29 ms
15,456 KB
testcase_20 AC 29 ms
15,492 KB
testcase_21 AC 29 ms
15,440 KB
testcase_22 AC 29 ms
15,316 KB
testcase_23 AC 26 ms
15,324 KB
testcase_24 AC 20 ms
15,304 KB
testcase_25 AC 25 ms
15,264 KB
testcase_26 AC 24 ms
15,268 KB
testcase_27 AC 29 ms
15,336 KB
testcase_28 AC 28 ms
15,496 KB
testcase_29 AC 20 ms
15,364 KB
testcase_30 AC 20 ms
15,528 KB
testcase_31 AC 26 ms
15,408 KB
testcase_32 AC 21 ms
15,488 KB
testcase_33 AC 25 ms
15,280 KB
testcase_34 AC 23 ms
15,380 KB
testcase_35 AC 29 ms
15,380 KB
testcase_36 AC 19 ms
15,392 KB
testcase_37 AC 27 ms
15,432 KB
testcase_38 AC 29 ms
15,388 KB
testcase_39 AC 24 ms
15,312 KB
testcase_40 AC 19 ms
15,252 KB
testcase_41 AC 19 ms
15,280 KB
testcase_42 AC 24 ms
15,220 KB
testcase_43 AC 17 ms
15,256 KB
testcase_44 AC 18 ms
15,284 KB
testcase_45 AC 17 ms
15,216 KB
testcase_46 AC 17 ms
15,384 KB
testcase_47 AC 18 ms
15,336 KB
testcase_48 AC 18 ms
15,440 KB
testcase_49 AC 18 ms
15,224 KB
testcase_50 AC 17 ms
15,256 KB
testcase_51 AC 17 ms
15,332 KB
testcase_52 AC 17 ms
15,324 KB
testcase_53 AC 18 ms
15,256 KB
testcase_54 AC 17 ms
15,424 KB
testcase_55 AC 18 ms
15,416 KB
testcase_56 AC 17 ms
15,316 KB
testcase_57 AC 18 ms
15,220 KB
testcase_58 AC 18 ms
15,264 KB
testcase_59 AC 17 ms
15,284 KB
testcase_60 AC 18 ms
15,372 KB
testcase_61 AC 17 ms
15,264 KB
testcase_62 AC 17 ms
15,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int sz = 510000;

i64 fac[sz], finv[sz], inv[sz];

void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(i64 i = 2; i < sz; ++i) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

i64 get(int n, int k) {
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

  int n;
  cin >> n;
  vt<int> a(n);
  rep(i, 0, n) cin >> a[i];
  init();

  i64 ans = 0;
  rep(i, 0, n) {
    ans += a[i] * get(n - 1, i);
    ans %= mod;
  }
  cout << ans << endl;
}
0