結果

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

ソースコード

diff #

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

const long long MOD = 1000000007ll;
long long fact[100100];

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

    fact[0] = 1;
    for ( int i = 1; i <= 100001; i++ ) {
        fact[i] = fact[i-1] * i;
        fact[i] %= MOD;
    }

    long long n;
    scanf("%lld", &n);
    for ( int i = 0; i < n; i++ ) {
        long long a;
        scanf("%lld", &a);
        ans += a * ( ( fact[n-1] * power ( (fact[i]*fact[n-1-i])%MOD, MOD-2) ) % MOD );
        ans %= MOD;
    }
    printf("%lld\n", ans);
    return 0;
}
0