結果

問題 No.797 Noelちゃんとピラミッド
ユーザー outlineoutline
提出日時 2020-03-28 18:49:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 4,057 bytes
コンパイル時間 1,310 ms
コンパイル使用メモリ 112,128 KB
実行使用メモリ 4,528 KB
最終ジャッジ日時 2023-08-30 18:06:07
合計ジャッジ時間 6,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 15 ms
4,380 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 15 ms
4,388 KB
testcase_06 AC 15 ms
4,380 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 15 ms
4,528 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 16 ms
4,380 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 15 ms
4,388 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 14 ms
4,384 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 15 ms
4,384 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 16 ms
4,380 KB
testcase_22 AC 15 ms
4,456 KB
testcase_23 AC 11 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 9 ms
4,376 KB
testcase_26 AC 9 ms
4,380 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 13 ms
4,384 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 11 ms
4,376 KB
testcase_32 AC 5 ms
4,376 KB
testcase_33 AC 9 ms
4,384 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 15 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 13 ms
4,376 KB
testcase_38 AC 13 ms
4,380 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 4 ms
4,380 KB
testcase_42 AC 9 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 2 ms
4,384 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 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,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

template<typename T>
struct Combination{
    int sz;
    vector<T> fact_;
    vector<T> ifact_;
    vector<T> inv_;
    
    Combination(int n = 1e+6) : sz(n) {
        fact_.resize(sz + 1);
        ifact_.resize(sz + 1);
        inv_.resize(sz + 1);

        fact_[0] = ifact_[sz] = inv_[0] = 1;
        for(int i = 1; i <= sz; ++i)    fact_[i] = fact_[i - 1] * i;
        ifact_[sz] /= fact_[sz];
        for(int i = sz; i > 0; --i)     ifact_[i - 1] = ifact_[i] * i;
        for(int i = 1; i <= sz; ++i)    inv_[i] = ifact_[i] * fact_[i - 1];
    }

    inline T fact(int k) const  {return fact_[k];}
    inline T ifact(int k) const {return ifact_[k];}
    inline T inv(int k) const   {return inv_[k];}

    T get_permutation(int n, int k){
        if(n < 0 || k < 0 || n < k)     return 0;
        return fact(n) * ifact(n - k);
    }

    T get_combination(int n, int k){
        if(n < 0 || k < 0 || n < k)     return 0;
        return fact(n) * ifact(k) * ifact(n - k);
    }
};

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

    int n;
    cin >> n;
    Combination<modint> c(n);
    modint ans = 0;
    for(int i = 0; i < n; ++i){
        modint a;
        cin >> a;
        ans += c.get_combination(n - 1, i) * a;
    }
    cout << ans << endl;
}
0