結果

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

ソースコード

diff #

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

long long power(long long x, long long n){
    long long res = 1;
    x %= MOD;
    while(n > 0LL){
        if(n & 1LL){
            res *= x;
            res %= MOD;
        }
        x *= x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}

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

    int n;
    cin >> n;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }

    vector<lint> fact(n), inv(n);
    fact[0] = 1;
    inv[0] = 1;
    REP(i, 1, n){
        fact[i] = (lint)i * fact[i - 1];
        fact[i] %= MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    lint ans = 0;
    rep(i, n){
        ans += (((fact[n - 1] * ((inv[i] * inv[n - 1 - i]) % MOD)) % MOD) * a[i]) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}
0