結果
| 問題 | 
                            No.797 Noelちゃんとピラミッド
                             | 
                    
| コンテスト | |
| ユーザー | 
                             t33f
                         | 
                    
| 提出日時 | 2019-03-17 18:49:25 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 58 ms / 2,000 ms | 
| コード長 | 935 bytes | 
| コンパイル時間 | 662 ms | 
| コンパイル使用メモリ | 70,064 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-07 14:06:52 | 
| 合計ジャッジ時間 | 5,127 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 60 | 
ソースコード
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define M 1000000007
long long fact[100002], facti[100002];
int modinv(int a, int m) {
    int x = m, y = a, p = 1, q = 0, r = 0, s = 1;
    while (y != 0) {
        int u = x / y;
        int x0 = y; y = x - y * u; x = x0;
        int r0 = p - r * u, s0 = q - s * u;
        p = r; r = r0; q = s; s = s0;
    }
    return q < 0 ? q + m : q;
}
long long mod_ch(int n, int k, int m) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * facti[k] % m * facti[n-k] % m;
}
int main () {
    fact[0] = 1; facti[0] = 1;
    for (int i = 1; i <= 100000; i++) {
        fact[i] = (fact[i-1] * i) % M;
        facti[i] = modinv(fact[i], M);
    }
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 0; i < n; i++) ans += mod_ch(n-1, i, M) * a[i] % M;
    cout << ans % M << endl;
}
            
            
            
        
            
t33f