結果

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

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

    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<ll> x(n+1,1);
    for(int i = 1; i < n+1; i++){
        x[i] = (x[i-1]*(ll)i)%MOD;
    }



    ll ans = 0;

    for(int i = 0; i < n; i++){
        ans += (a[i]*((x[n-1]*((mypow(x[i],MOD-2)*mypow(x[n-i-1],MOD-2))%MOD))%MOD) )%MOD;
        ans %= MOD;
    }

    cout << ans << endl;
    
    return 0;
}
0