結果
| 問題 | 
                            No.797 Noelちゃんとピラミッド
                             | 
                    
| コンテスト | |
| ユーザー | 
                             merom686
                         | 
                    
| 提出日時 | 2019-03-16 09:05:58 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 26 ms / 2,000 ms | 
| コード長 | 767 bytes | 
| コンパイル時間 | 619 ms | 
| コンパイル使用メモリ | 73,840 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-01 22:22:06 | 
| 合計ジャッジ時間 | 3,373 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 60 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
constexpr int P = 1000000007;
int inv(int n) {
    int m = P, y = 0, v = 1;
    while (1) {
        int q = m / n;
        int r = m % n;
        if (r == 0) return v < 0 ? v + P : v;
        y -= v * q;
        swap(y, v);
        m = n;
        n = r;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int m = n - 1;
    ll s = 0, t = 1;
    for (int i = 0; i <= m; i++) {
        int a;
        cin >> a;
        s += a * t;
        s %= P;
        t = t * (m - i) % P * inv(i + 1) % P;
    }
    cout << s << endl;
    return 0;
}
            
            
            
        
            
merom686