結果

問題 No.797 Noelちゃんとピラミッド
ユーザー Tiramister
提出日時 2019-03-15 23:54:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 65,580 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 22:08:32
合計ジャッジ時間 3,947 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

template <typename T, typename U>
T mpow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * b % MOD;
        n >>= 1;
        b = b * b % MOD;
    }
    return ret;
}

const ll MAX_V = 100010;
ll fact[MAX_V + 1], invfact[MAX_V + 1];

void precalc() {
    invfact[0] = fact[0] = 1;
    for (ll i = 1; i <= MAX_V; ++i) {
        fact[i] = fact[i - 1] * i % MOD;
    }

    invfact[MAX_V] = mpow(fact[MAX_V], MOD - 2);
    for (ll i = MAX_V - 1; i >= 0; --i) {
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
    return;
}

ll comb(ll a, ll b) {
    if (a < b) return 0;
    if (a == 0) return 1;  // a = b = 0
    return fact[a] * invfact[a - b] % MOD * invfact[b] % MOD;
}

int main() {
    precalc();
    int N;
    cin >> N;
    ll ans = 0;
    for (ll i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        ans += a * comb(N - 1, i) % MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}
0