結果

問題 No.797 Noelちゃんとピラミッド
ユーザー toyama
提出日時 2019-03-15 22:40:16
言語 C
(gcc 8.2.0)
結果
AC  
実行時間 31 ms
コード長 1,155 Byte
コンパイル時間 111 ms
使用メモリ 3,712 KB
最終ジャッジ日時 2019-03-15 22:40:20

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
LEARGE_case1.txt AC 20 ms
3,708 KB
LEARGE_case2.txt AC 19 ms
3,712 KB
LEARGE_case3.txt AC 20 ms
3,712 KB
LEARGE_case4.txt AC 20 ms
3,712 KB
LEARGE_case5.txt AC 19 ms
3,712 KB
LEARGE_case6.txt AC 20 ms
3,708 KB
LEARGE_case7.txt AC 20 ms
3,708 KB
LEARGE_case8.txt AC 20 ms
3,708 KB
LEARGE_case9.txt AC 20 ms
3,712 KB
LEARGE_case10.txt AC 20 ms
3,708 KB
LEARGE_case11.txt AC 20 ms
3,708 KB
LEARGE_case12.txt AC 26 ms
3,708 KB
LEARGE_case13.txt AC 19 ms
3,712 KB
LEARGE_case14.txt AC 25 ms
3,712 KB
LEARGE_case15.txt AC 24 ms
3,712 KB
LEARGE_case16.txt AC 31 ms
3,708 KB
LEARGE_case17.txt AC 19 ms
3,708 KB
LEARGE_case18.txt AC 19 ms
3,712 KB
LEARGE_case19.txt AC 20 ms
3,708 KB
LEARGE_case20.txt AC 20 ms
3,712 KB
RANDOM_case1.txt AC 16 ms
3,496 KB
RANDOM_case2.txt AC 10 ms
3,108 KB
RANDOM_case3.txt AC 15 ms
3,408 KB
RANDOM_case4.txt AC 15 ms
3,384 KB
RANDOM_case5.txt AC 20 ms
3,700 KB
RANDOM_case6.txt AC 19 ms
3,628 KB
RANDOM_case7.txt AC 9 ms
3,040 KB
RANDOM_case8.txt AC 11 ms
3,100 KB
RANDOM_case9.txt AC 16 ms
3,496 KB
RANDOM_case10.txt AC 12 ms
3,172 KB
RANDOM_case11.txt AC 15 ms
3,396 KB
RANDOM_case12.txt AC 13 ms
3,260 KB
RANDOM_case13.txt AC 19 ms
3,712 KB
RANDOM_case14.txt AC 8 ms
3,016 KB
RANDOM_case15.txt AC 18 ms
3,620 KB
RANDOM_case16.txt AC 19 ms
3,660 KB
RANDOM_case17.txt AC 14 ms
3,392 KB
RANDOM_case18.txt AC 9 ms
3,020 KB
RANDOM_case19.txt AC 9 ms
3,068 KB
RANDOM_case20.txt AC 15 ms
3,372 KB
SMALL_case1.txt AC 8 ms
2,940 KB
SMALL_case2.txt AC 7 ms
2,940 KB
SMALL_case3.txt AC 8 ms
2,940 KB
SMALL_case4.txt AC 8 ms
2,940 KB
SMALL_case5.txt AC 8 ms
2,940 KB
SMALL_case6.txt AC 7 ms
2,944 KB
SMALL_case7.txt AC 7 ms
2,940 KB
SMALL_case8.txt AC 8 ms
2,940 KB
SMALL_case9.txt AC 8 ms
2,944 KB
SMALL_case10.txt AC 8 ms
2,944 KB
SMALL_case11.txt AC 8 ms
2,944 KB
SMALL_case12.txt AC 8 ms
2,940 KB
SMALL_case13.txt AC 8 ms
2,940 KB
SMALL_case14.txt AC 7 ms
2,940 KB
SMALL_case15.txt AC 7 ms
2,940 KB
SMALL_case16.txt AC 8 ms
2,936 KB
SMALL_case17.txt AC 8 ms
2,944 KB
SMALL_case18.txt AC 8 ms
2,940 KB
SMALL_case19.txt AC 7 ms
2,936 KB
SMALL_case20.txt AC 8 ms
2,936 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <stdio.h>
#define MOD ((long long)(1e9) + 7)
typedef long long ll;

ll fact[100005], finv[100005], inv[100005];

void init()
{
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (ll i = 2; i < 100005; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    return;
}

long long com(int n, int k)
{
    if (n < k) {
        return 0;
    }
    
    if (n < 0 || k < 0) {
        return 0;
    }
    
    return fact[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    init();
    
    int n;
    unsigned long long a[100005];
    unsigned long long ans = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%llu", &a[i]);
    }
    
    /*
    for (int i = 1; i <= 10; i++) {
        for (int j = 0; j <= i; j++) {
            printf("%4lld ", com(i, j));
        }
        putchar('\n');
    }
    */

    for (int r = 0; r < n; r++) {
        ans = ans + (a[r] * (unsigned long long)com(n - 1, r)) % MOD;
        ans = ans % MOD;
    }

    printf("%llu\n", ans);

    return 0;
}
0