結果

問題 No.797 Noelちゃんとピラミッド
ユーザー null_mnnull_mn
提出日時 2019-03-20 21:07:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 2,122 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 162,044 KB
実行使用メモリ 5,948 KB
最終ジャッジ日時 2023-10-19 04:35:17
合計ジャッジ時間 5,148 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
5,164 KB
testcase_01 AC 16 ms
5,164 KB
testcase_02 AC 16 ms
5,164 KB
testcase_03 AC 29 ms
5,948 KB
testcase_04 AC 29 ms
5,948 KB
testcase_05 AC 28 ms
5,948 KB
testcase_06 AC 29 ms
5,948 KB
testcase_07 AC 29 ms
5,948 KB
testcase_08 AC 29 ms
5,948 KB
testcase_09 AC 29 ms
5,948 KB
testcase_10 AC 28 ms
5,948 KB
testcase_11 AC 29 ms
5,948 KB
testcase_12 AC 29 ms
5,948 KB
testcase_13 AC 29 ms
5,948 KB
testcase_14 AC 29 ms
5,948 KB
testcase_15 AC 29 ms
5,948 KB
testcase_16 AC 29 ms
5,948 KB
testcase_17 AC 28 ms
5,948 KB
testcase_18 AC 29 ms
5,948 KB
testcase_19 AC 28 ms
5,948 KB
testcase_20 AC 29 ms
5,948 KB
testcase_21 AC 29 ms
5,948 KB
testcase_22 AC 29 ms
5,948 KB
testcase_23 AC 25 ms
5,724 KB
testcase_24 AC 19 ms
5,340 KB
testcase_25 AC 24 ms
5,636 KB
testcase_26 AC 23 ms
5,608 KB
testcase_27 AC 29 ms
5,928 KB
testcase_28 AC 28 ms
5,852 KB
testcase_29 AC 18 ms
5,264 KB
testcase_30 AC 19 ms
5,328 KB
testcase_31 AC 25 ms
5,720 KB
testcase_32 AC 20 ms
5,396 KB
testcase_33 AC 23 ms
5,624 KB
testcase_34 AC 22 ms
5,488 KB
testcase_35 AC 29 ms
5,948 KB
testcase_36 AC 17 ms
5,248 KB
testcase_37 AC 27 ms
5,848 KB
testcase_38 AC 27 ms
5,880 KB
testcase_39 AC 23 ms
5,616 KB
testcase_40 AC 18 ms
5,244 KB
testcase_41 AC 18 ms
5,288 KB
testcase_42 AC 23 ms
5,596 KB
testcase_43 AC 17 ms
5,168 KB
testcase_44 AC 16 ms
5,168 KB
testcase_45 AC 16 ms
5,168 KB
testcase_46 AC 16 ms
5,168 KB
testcase_47 AC 16 ms
5,168 KB
testcase_48 AC 17 ms
5,168 KB
testcase_49 AC 17 ms
5,168 KB
testcase_50 AC 16 ms
5,168 KB
testcase_51 AC 16 ms
5,168 KB
testcase_52 AC 16 ms
5,168 KB
testcase_53 AC 16 ms
5,168 KB
testcase_54 AC 16 ms
5,164 KB
testcase_55 AC 17 ms
5,168 KB
testcase_56 AC 17 ms
5,168 KB
testcase_57 AC 16 ms
5,168 KB
testcase_58 AC 16 ms
5,164 KB
testcase_59 AC 16 ms
5,168 KB
testcase_60 AC 17 ms
5,168 KB
testcase_61 AC 17 ms
5,168 KB
testcase_62 AC 17 ms
5,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------
const ll MAX_N = 100010;
ll fact[MAX_N];
ll fact_inv[MAX_N];

ll pow_mod(ll x, ll y, ll m = MOD) { //x^y mod m
    if (x == 0) return 0;
    ll prod = 1;
    while (y > 0) {
        if (y % 2 == 1) prod = (prod * x) % m;
        x = (x * x) % m;
        y /= 2;
    }
    return prod % m;
}

void init_fact() {
    fact[0] = fact_inv[0] = 1;

    REP(i, 1, MAX_N) {
        fact[i] = (fact[i - 1] * i) % MOD;
        fact_inv[i] = pow_mod(fact[i], MOD - 2);
    }
}

ll C_mod(ll n, ll r) {
    if (n < r) return 0;
    else return ((fact[n] * fact_inv[n - r]) % MOD * fact_inv[r]) % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    init_fact();
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += a[i] * C_mod(n - 1, i);
        sum %= MOD;
    }
    cout << sum << endl;
    return 0;
}
0