結果

問題 No.797 Noelちゃんとピラミッド
ユーザー face4face4
提出日時 2019-03-15 21:31:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 69,772 KB
実行使用メモリ 5,652 KB
最終ジャッジ日時 2023-09-14 13:02:42
合計ジャッジ時間 4,369 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,568 KB
testcase_01 AC 4 ms
4,524 KB
testcase_02 AC 4 ms
4,568 KB
testcase_03 AC 42 ms
5,428 KB
testcase_04 AC 42 ms
5,456 KB
testcase_05 AC 42 ms
5,432 KB
testcase_06 AC 41 ms
5,368 KB
testcase_07 AC 42 ms
5,316 KB
testcase_08 AC 42 ms
5,500 KB
testcase_09 AC 42 ms
5,404 KB
testcase_10 AC 42 ms
5,432 KB
testcase_11 AC 42 ms
5,488 KB
testcase_12 AC 42 ms
5,432 KB
testcase_13 AC 42 ms
5,412 KB
testcase_14 AC 41 ms
5,360 KB
testcase_15 AC 41 ms
5,384 KB
testcase_16 AC 42 ms
5,360 KB
testcase_17 AC 42 ms
5,432 KB
testcase_18 AC 42 ms
5,316 KB
testcase_19 AC 42 ms
5,436 KB
testcase_20 AC 42 ms
5,384 KB
testcase_21 AC 42 ms
5,316 KB
testcase_22 AC 42 ms
5,376 KB
testcase_23 AC 32 ms
5,160 KB
testcase_24 AC 12 ms
4,528 KB
testcase_25 AC 27 ms
5,052 KB
testcase_26 AC 26 ms
5,164 KB
testcase_27 AC 41 ms
5,316 KB
testcase_28 AC 37 ms
5,644 KB
testcase_29 AC 8 ms
4,568 KB
testcase_30 AC 12 ms
4,580 KB
testcase_31 AC 31 ms
5,160 KB
testcase_32 AC 15 ms
4,928 KB
testcase_33 AC 26 ms
5,056 KB
testcase_34 AC 19 ms
5,128 KB
testcase_35 AC 42 ms
5,616 KB
testcase_36 AC 7 ms
4,696 KB
testcase_37 AC 37 ms
5,652 KB
testcase_38 AC 39 ms
5,424 KB
testcase_39 AC 26 ms
5,220 KB
testcase_40 AC 8 ms
4,660 KB
testcase_41 AC 10 ms
4,524 KB
testcase_42 AC 25 ms
4,832 KB
testcase_43 AC 4 ms
4,696 KB
testcase_44 AC 4 ms
4,640 KB
testcase_45 AC 4 ms
4,564 KB
testcase_46 AC 4 ms
4,568 KB
testcase_47 AC 4 ms
4,620 KB
testcase_48 AC 4 ms
4,524 KB
testcase_49 AC 4 ms
4,692 KB
testcase_50 AC 4 ms
4,660 KB
testcase_51 AC 4 ms
4,684 KB
testcase_52 AC 4 ms
4,736 KB
testcase_53 AC 4 ms
4,568 KB
testcase_54 AC 4 ms
4,824 KB
testcase_55 AC 4 ms
4,636 KB
testcase_56 AC 4 ms
4,700 KB
testcase_57 AC 4 ms
4,672 KB
testcase_58 AC 4 ms
4,696 KB
testcase_59 AC 4 ms
4,640 KB
testcase_60 AC 4 ms
4,652 KB
testcase_61 AC 4 ms
4,668 KB
testcase_62 AC 4 ms
4,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    int n;
    cin >> n;

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

    ModComb mc(100001);

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += mc.nCk(n-1, i) * a[i];
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}
0