結果

問題 No.797 Noelちゃんとピラミッド
ユーザー pianonekopianoneko
提出日時 2019-03-19 18:07:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,538 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 166,756 KB
実行使用メモリ 5,700 KB
最終ジャッジ日時 2023-10-12 02:45:21
合計ジャッジ時間 7,342 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,388 KB
testcase_01 AC 20 ms
4,584 KB
testcase_02 AC 20 ms
4,572 KB
testcase_03 AC 59 ms
5,380 KB
testcase_04 AC 58 ms
5,428 KB
testcase_05 AC 58 ms
5,536 KB
testcase_06 AC 58 ms
5,528 KB
testcase_07 AC 58 ms
5,668 KB
testcase_08 AC 58 ms
5,400 KB
testcase_09 AC 58 ms
5,488 KB
testcase_10 AC 58 ms
5,380 KB
testcase_11 AC 58 ms
5,532 KB
testcase_12 AC 58 ms
5,516 KB
testcase_13 AC 58 ms
5,436 KB
testcase_14 AC 58 ms
5,468 KB
testcase_15 AC 58 ms
5,468 KB
testcase_16 AC 58 ms
5,396 KB
testcase_17 AC 58 ms
5,472 KB
testcase_18 AC 58 ms
5,420 KB
testcase_19 AC 58 ms
5,508 KB
testcase_20 AC 58 ms
5,528 KB
testcase_21 AC 58 ms
5,468 KB
testcase_22 AC 58 ms
5,700 KB
testcase_23 AC 47 ms
5,224 KB
testcase_24 AC 28 ms
4,852 KB
testcase_25 AC 43 ms
5,140 KB
testcase_26 AC 41 ms
5,156 KB
testcase_27 AC 57 ms
5,352 KB
testcase_28 AC 53 ms
5,116 KB
testcase_29 AC 25 ms
4,580 KB
testcase_30 AC 28 ms
4,684 KB
testcase_31 AC 47 ms
5,168 KB
testcase_32 AC 31 ms
5,152 KB
testcase_33 AC 42 ms
5,268 KB
testcase_34 AC 37 ms
4,908 KB
testcase_35 AC 58 ms
5,484 KB
testcase_36 AC 24 ms
4,576 KB
testcase_37 AC 54 ms
5,148 KB
testcase_38 AC 55 ms
5,540 KB
testcase_39 AC 42 ms
5,160 KB
testcase_40 AC 24 ms
4,528 KB
testcase_41 AC 26 ms
4,580 KB
testcase_42 AC 41 ms
5,204 KB
testcase_43 AC 20 ms
4,524 KB
testcase_44 AC 20 ms
4,492 KB
testcase_45 AC 20 ms
4,684 KB
testcase_46 AC 20 ms
4,396 KB
testcase_47 AC 20 ms
4,564 KB
testcase_48 AC 20 ms
4,500 KB
testcase_49 AC 20 ms
4,412 KB
testcase_50 AC 20 ms
4,708 KB
testcase_51 AC 20 ms
4,576 KB
testcase_52 AC 20 ms
4,612 KB
testcase_53 AC 20 ms
4,700 KB
testcase_54 AC 20 ms
4,648 KB
testcase_55 AC 20 ms
4,500 KB
testcase_56 AC 20 ms
4,584 KB
testcase_57 AC 20 ms
4,412 KB
testcase_58 AC 20 ms
4,628 KB
testcase_59 AC 20 ms
4,436 KB
testcase_60 AC 20 ms
4,712 KB
testcase_61 AC 20 ms
4,504 KB
testcase_62 AC 20 ms
4,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

const int MAX = 100000;

vector<long long> fac(MAX + 1), inverseFac(MAX + 1);

long long modPow(long long x, long long n) {
    long long ans = 1;
    while (n != 0) {
        if (n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

long long comb(long long a, long long b) {
    if (a == 0 && b == 0) return 1;
    if (a < b || a < 0) return 0;
    long long tmp = inverseFac[a - b] * inverseFac[b] % MOD;
    return tmp * fac[a] % MOD;
}

long long perm(long long a, long long b) {
    if (a < b) return 0;
    long long tmp = inverseFac[a - b] % MOD;
    return tmp * fac[a] % MOD;
}

long long dupc(long long a, long long b) {
    if (a == 0 && b == 0) return 1;
    if (a < 0 || b == 0) return 0;
    long long tmp = inverseFac[a - 1] * inverseFac[b] % MOD;
    return tmp * fac[a + b - 1] % MOD;
}

void init() {
    fac[0] = 1;
    inverseFac[0] = 1;
    for (long long i = 0; i < MAX; i++) {
        fac[i + 1] = fac[i] * (i + 1) % MOD;
        inverseFac[i + 1] = inverseFac[i] * modPow(i + 1, MOD - 2) % MOD;
    }
}

int main() {
    int N;
    cin >> N;
    vector<long long> a(N);
    REP(i, N) {
        cin >> a[i];
    }

    init();
    long long ans = 0;
    REP(i, N) {
        ans += comb(N - 1, i) * a[i];
        ans %= MOD;
    }

    cout << ans << endl;
}
0