結果

問題 No.797 Noelちゃんとピラミッド
ユーザー maguromaguro
提出日時 2022-05-18 18:57:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,926 bytes
コンパイル時間 2,357 ms
コンパイル使用メモリ 202,240 KB
実行使用メモリ 6,308 KB
最終ジャッジ日時 2023-10-15 03:57:58
合計ジャッジ時間 8,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 45 ms
6,136 KB
testcase_04 AC 46 ms
6,224 KB
testcase_05 AC 45 ms
6,304 KB
testcase_06 AC 46 ms
6,308 KB
testcase_07 AC 45 ms
6,308 KB
testcase_08 AC 45 ms
6,132 KB
testcase_09 AC 45 ms
6,192 KB
testcase_10 AC 45 ms
6,308 KB
testcase_11 AC 45 ms
6,128 KB
testcase_12 AC 46 ms
6,184 KB
testcase_13 AC 45 ms
6,188 KB
testcase_14 AC 45 ms
6,196 KB
testcase_15 AC 45 ms
6,304 KB
testcase_16 AC 45 ms
6,268 KB
testcase_17 AC 46 ms
6,308 KB
testcase_18 AC 46 ms
6,232 KB
testcase_19 AC 45 ms
6,204 KB
testcase_20 AC 45 ms
6,272 KB
testcase_21 AC 45 ms
6,128 KB
testcase_22 AC 45 ms
6,268 KB
testcase_23 AC 33 ms
5,080 KB
testcase_24 AC 11 ms
4,372 KB
testcase_25 AC 28 ms
4,956 KB
testcase_26 AC 26 ms
4,812 KB
testcase_27 AC 45 ms
6,220 KB
testcase_28 AC 40 ms
5,604 KB
testcase_29 AC 8 ms
4,368 KB
testcase_30 AC 11 ms
4,372 KB
testcase_31 AC 33 ms
5,208 KB
testcase_32 AC 15 ms
4,372 KB
testcase_33 AC 27 ms
4,860 KB
testcase_34 AC 19 ms
4,376 KB
testcase_35 AC 45 ms
6,268 KB
testcase_36 AC 6 ms
4,372 KB
testcase_37 AC 40 ms
5,780 KB
testcase_38 AC 42 ms
5,928 KB
testcase_39 AC 26 ms
4,856 KB
testcase_40 AC 6 ms
4,368 KB
testcase_41 AC 9 ms
4,372 KB
testcase_42 AC 26 ms
5,164 KB
testcase_43 AC 2 ms
4,372 KB
testcase_44 AC 1 ms
4,368 KB
testcase_45 AC 2 ms
4,368 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,368 KB
testcase_48 AC 1 ms
4,372 KB
testcase_49 AC 1 ms
4,368 KB
testcase_50 AC 1 ms
4,372 KB
testcase_51 AC 2 ms
4,372 KB
testcase_52 AC 2 ms
4,372 KB
testcase_53 AC 1 ms
4,372 KB
testcase_54 AC 1 ms
4,372 KB
testcase_55 AC 1 ms
4,372 KB
testcase_56 AC 1 ms
4,372 KB
testcase_57 AC 1 ms
4,376 KB
testcase_58 AC 2 ms
4,368 KB
testcase_59 AC 2 ms
4,372 KB
testcase_60 AC 2 ms
4,368 KB
testcase_61 AC 2 ms
4,372 KB
testcase_62 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
constexpr int Inf = 2000000000;
constexpr long long INF= 2000000000000000000;

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T,typename U>
T modpow(T N, U P, T M = -1) {
    if(P < 0) return 0;
    T ret = 1;
    if(M != -1) ret %= M;
    while(P) {
        if(P & 1) {
            if(M == -1) ret *= N;
            else ret = ret * N % M;
        }
        P /= 2;
        if(M == -1) N *= N;
        else N = N * N % M;
    }
    return ret;
}

constexpr long long MOD = 1000000007;

struct Comb {
    int size;
    long long mod;
    std::vector<long long> factorial;
    std::vector<long long> inversion_factorial;
    std::vector<long long> inversion;

    Comb(int n,long long mod): size(n),mod(mod) {
        factorial.resize(n + 1);
        inversion_factorial.resize(n + 1);
        inversion.resize(n + 1);
        factorial[0] = factorial[1] = 1;
        inversion_factorial[0] = inversion_factorial[1] = 1;
        inversion[1] = 1;
        for (long long i = 2; i <= n; i++) {
            factorial[i] = factorial[i - 1] * i % mod;
            inversion[i] = mod - inversion[mod % i] * (mod / i) % mod;
            inversion_factorial[i] = inversion_factorial[i - 1] * inversion[i] % mod;
        }
    }

    long long comb(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return factorial[n] * (inversion_factorial[k] * inversion_factorial[n - k] % mod) % mod;
    }
};

int main() {
    int n;
    cin >> n;
    vector<long long> vec(n);
    for(auto& x: vec) cin >> x;

    Comb comb(n,MOD);

    long long ret = 0;
    for(int i = 0;i < n;i++) {
        ret += vec[i] * comb.comb(n - 1,i);
        ret %= MOD;
    }
    cout << ret << endl;
}
0