結果

問題 No.797 Noelちゃんとピラミッド
ユーザー tottoripapertottoripaper
提出日時 2019-03-16 01:02:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,946 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 176,228 KB
実行使用メモリ 7,148 KB
最終ジャッジ日時 2023-09-14 14:55:39
合計ジャッジ時間 4,974 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,084 KB
testcase_01 AC 10 ms
5,996 KB
testcase_02 AC 11 ms
6,208 KB
testcase_03 AC 24 ms
6,916 KB
testcase_04 AC 24 ms
6,980 KB
testcase_05 AC 24 ms
6,868 KB
testcase_06 AC 24 ms
6,868 KB
testcase_07 AC 24 ms
6,908 KB
testcase_08 AC 24 ms
6,996 KB
testcase_09 AC 24 ms
6,964 KB
testcase_10 AC 24 ms
6,912 KB
testcase_11 AC 24 ms
6,988 KB
testcase_12 AC 24 ms
6,912 KB
testcase_13 AC 24 ms
6,908 KB
testcase_14 AC 24 ms
6,908 KB
testcase_15 AC 24 ms
6,984 KB
testcase_16 AC 23 ms
6,904 KB
testcase_17 AC 24 ms
6,876 KB
testcase_18 AC 24 ms
6,876 KB
testcase_19 AC 23 ms
6,876 KB
testcase_20 AC 24 ms
7,148 KB
testcase_21 AC 24 ms
6,876 KB
testcase_22 AC 24 ms
6,908 KB
testcase_23 AC 20 ms
6,732 KB
testcase_24 AC 13 ms
6,436 KB
testcase_25 AC 19 ms
6,608 KB
testcase_26 AC 18 ms
6,720 KB
testcase_27 AC 23 ms
6,960 KB
testcase_28 AC 23 ms
7,008 KB
testcase_29 AC 12 ms
6,236 KB
testcase_30 AC 13 ms
5,908 KB
testcase_31 AC 20 ms
6,584 KB
testcase_32 AC 14 ms
6,380 KB
testcase_33 AC 19 ms
6,608 KB
testcase_34 AC 16 ms
6,616 KB
testcase_35 AC 25 ms
7,056 KB
testcase_36 AC 12 ms
6,000 KB
testcase_37 AC 22 ms
6,672 KB
testcase_38 AC 23 ms
6,936 KB
testcase_39 AC 18 ms
6,668 KB
testcase_40 AC 12 ms
5,944 KB
testcase_41 AC 13 ms
6,092 KB
testcase_42 AC 18 ms
6,720 KB
testcase_43 AC 11 ms
6,060 KB
testcase_44 AC 10 ms
6,056 KB
testcase_45 AC 10 ms
6,132 KB
testcase_46 AC 10 ms
6,108 KB
testcase_47 AC 11 ms
6,084 KB
testcase_48 AC 11 ms
6,084 KB
testcase_49 AC 10 ms
6,136 KB
testcase_50 AC 11 ms
5,904 KB
testcase_51 AC 10 ms
5,916 KB
testcase_52 AC 11 ms
5,948 KB
testcase_53 AC 11 ms
6,156 KB
testcase_54 AC 11 ms
6,136 KB
testcase_55 AC 11 ms
5,912 KB
testcase_56 AC 11 ms
5,940 KB
testcase_57 AC 11 ms
6,092 KB
testcase_58 AC 10 ms
6,004 KB
testcase_59 AC 10 ms
6,084 KB
testcase_60 AC 11 ms
6,220 KB
testcase_61 AC 11 ms
5,948 KB
testcase_62 AC 10 ms
6,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    T s1 = 1, t1 = 0, s2 = 0, t2 = 1;
    while(b != 0){
        std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2);
        std::tie(a, b) = std::make_tuple(b, a % b);
    }
    return std::make_tuple(s1, t1, a);
}

// 注意: a と mod が互いに素である必要がある
template <typename T>
T mod_inverse(T a, T mod){
    T b;
    std::tie(b, std::ignore, std::ignore) = extgcd(a, mod);
    if(b < 0){b += mod;}
    return b;
}

template <typename T>
struct Combinatorics{
    T modulo;
    std::vector<T> fact, inv_fact;

    Combinatorics(T max, T modulo) : modulo(modulo), fact(max + 1), inv_fact(max + 1) {
        fact[0] = 1;
        for(T i=1;i<=max;++i){
            fact[i] = i * fact[i - 1] % modulo;
        }

        inv_fact[max] = mod_inverse(fact[max], modulo);
        for(T i=max;i>0;--i){
            inv_fact[i - 1] = i * inv_fact[i] % modulo;
        }
    }

    T nPk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[n - k] % modulo;
    }

    T nCk(T n, T k){
        if(n < k){return 0;}
        return fact[n] * inv_fact[k] % modulo * inv_fact[n - k] % modulo;
    }

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

constexpr ll MOD = 1'000'000'007;
Combinatorics<ll> comb(200100, MOD);

int N;
ll A[100100];

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    ll v = 0;
    for(int i=0;i<N;++i){
        v = (v + A[i] * comb.nCk(N - 1, i)) % MOD;
    }

    std::cout << v << std::endl;
}
0