結果

問題 No.797 Noelちゃんとピラミッド
ユーザー kappybarkappybar
提出日時 2020-04-12 14:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 1,579 ms
コンパイル使用メモリ 169,916 KB
実行使用メモリ 27,648 KB
最終ジャッジ日時 2023-10-22 01:16:15
合計ジャッジ時間 8,531 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
27,104 KB
testcase_01 AC 25 ms
27,104 KB
testcase_02 AC 25 ms
27,104 KB
testcase_03 AC 67 ms
27,648 KB
testcase_04 AC 69 ms
27,648 KB
testcase_05 AC 65 ms
27,648 KB
testcase_06 AC 65 ms
27,648 KB
testcase_07 AC 69 ms
27,648 KB
testcase_08 AC 67 ms
27,648 KB
testcase_09 AC 65 ms
27,648 KB
testcase_10 AC 64 ms
27,648 KB
testcase_11 AC 65 ms
27,648 KB
testcase_12 AC 65 ms
27,648 KB
testcase_13 AC 64 ms
27,648 KB
testcase_14 AC 65 ms
27,648 KB
testcase_15 AC 66 ms
27,648 KB
testcase_16 AC 67 ms
27,648 KB
testcase_17 AC 68 ms
27,648 KB
testcase_18 AC 69 ms
27,648 KB
testcase_19 AC 67 ms
27,648 KB
testcase_20 AC 67 ms
27,648 KB
testcase_21 AC 68 ms
27,648 KB
testcase_22 AC 64 ms
27,648 KB
testcase_23 AC 55 ms
27,384 KB
testcase_24 AC 34 ms
27,104 KB
testcase_25 AC 50 ms
27,120 KB
testcase_26 AC 49 ms
27,120 KB
testcase_27 AC 66 ms
27,648 KB
testcase_28 AC 61 ms
27,384 KB
testcase_29 AC 32 ms
27,204 KB
testcase_30 AC 37 ms
27,104 KB
testcase_31 AC 55 ms
27,384 KB
testcase_32 AC 37 ms
27,120 KB
testcase_33 AC 48 ms
27,120 KB
testcase_34 AC 43 ms
27,120 KB
testcase_35 AC 67 ms
27,648 KB
testcase_36 AC 29 ms
27,188 KB
testcase_37 AC 61 ms
27,384 KB
testcase_38 AC 63 ms
27,384 KB
testcase_39 AC 48 ms
27,120 KB
testcase_40 AC 29 ms
27,184 KB
testcase_41 AC 34 ms
27,228 KB
testcase_42 AC 49 ms
27,120 KB
testcase_43 AC 26 ms
27,108 KB
testcase_44 AC 26 ms
27,108 KB
testcase_45 AC 27 ms
27,108 KB
testcase_46 AC 26 ms
27,108 KB
testcase_47 AC 30 ms
27,104 KB
testcase_48 AC 27 ms
27,108 KB
testcase_49 AC 26 ms
27,108 KB
testcase_50 AC 27 ms
27,108 KB
testcase_51 AC 26 ms
27,108 KB
testcase_52 AC 26 ms
27,108 KB
testcase_53 AC 26 ms
27,108 KB
testcase_54 AC 26 ms
27,104 KB
testcase_55 AC 26 ms
27,108 KB
testcase_56 AC 25 ms
27,108 KB
testcase_57 AC 28 ms
27,108 KB
testcase_58 AC 27 ms
27,104 KB
testcase_59 AC 26 ms
27,108 KB
testcase_60 AC 27 ms
27,104 KB
testcase_61 AC 26 ms
27,104 KB
testcase_62 AC 26 ms
27,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const int INF = 1e9;
const int MOD = 1000000007;

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n){
        ans = (ans + (a[i] * COM(n-1,i))%MOD)%MOD;
    }
    cout << ans << endl;
    return 0;
}
0