結果

問題 No.797 Noelちゃんとピラミッド
ユーザー mamekinmamekin
提出日時 2019-03-15 21:29:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 2,062 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 120,708 KB
実行使用メモリ 5,912 KB
最終ジャッジ日時 2023-09-14 12:59:18
合計ジャッジ時間 4,951 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 46 ms
5,684 KB
testcase_04 AC 46 ms
5,688 KB
testcase_05 AC 46 ms
5,692 KB
testcase_06 AC 46 ms
5,748 KB
testcase_07 AC 46 ms
5,716 KB
testcase_08 AC 46 ms
5,764 KB
testcase_09 AC 46 ms
5,640 KB
testcase_10 AC 46 ms
5,724 KB
testcase_11 AC 46 ms
5,628 KB
testcase_12 AC 46 ms
5,624 KB
testcase_13 AC 46 ms
5,620 KB
testcase_14 AC 46 ms
5,620 KB
testcase_15 AC 46 ms
5,628 KB
testcase_16 AC 46 ms
5,720 KB
testcase_17 AC 46 ms
5,912 KB
testcase_18 AC 46 ms
5,620 KB
testcase_19 AC 47 ms
5,580 KB
testcase_20 AC 46 ms
5,692 KB
testcase_21 AC 46 ms
5,636 KB
testcase_22 AC 46 ms
5,872 KB
testcase_23 AC 33 ms
4,956 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 28 ms
4,520 KB
testcase_26 AC 27 ms
4,588 KB
testcase_27 AC 45 ms
5,632 KB
testcase_28 AC 41 ms
5,420 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 11 ms
4,376 KB
testcase_31 AC 34 ms
4,828 KB
testcase_32 AC 15 ms
4,380 KB
testcase_33 AC 28 ms
4,572 KB
testcase_34 AC 20 ms
4,380 KB
testcase_35 AC 46 ms
5,620 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 41 ms
5,524 KB
testcase_38 AC 42 ms
5,880 KB
testcase_39 AC 28 ms
4,580 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 9 ms
4,380 KB
testcase_42 AC 26 ms
4,696 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void mod_inverse(int n, vector<long long>& inv, int mod)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}

class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        vector<long long> inv;
        mod_inverse(n, inv, mod);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getInvFactorial(int n){
        return invFactorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        return getCombination(n+r-1, r);
    }
};

const int MOD = 1000000007;

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

    FactorialCalculation fc(n, MOD);
    long long ans = 0;
    for(int i=0; i<n; ++i){
        ans += a[i] * fc.getCombination(n-1, i);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}
0