結果
| 問題 | No.797 Noelちゃんとピラミッド |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-19 14:53:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 1,089 bytes |
| 記録 | |
| コンパイル時間 | 1,572 ms |
| コンパイル使用メモリ | 166,536 KB |
| 実行使用メモリ | 8,244 KB |
| 最終ジャッジ日時 | 2024-09-13 19:58:45 |
| 合計ジャッジ時間 | 6,027 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX_N 200010
long long inv[MAX_N];
long long factorial[MAX_N];
long long inv_factorial[MAX_N];
void GetInv(){
for (int i = 1; i < MAX_N; i++) {
if (i == 1) inv[i] = 1;
else {
inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
if (inv[i] < 0) inv[i] += mod;
}
}
}
void GetFactorial(){
factorial[0] = 1; inv_factorial[0] = 1;
for (int i = 1; i < MAX_N; i++) {
factorial[i] = factorial[i-1] * i;
factorial[i] %= mod;
inv_factorial[i] = inv_factorial[i-1] * inv[i];
inv_factorial[i] %= mod;
}
}
long long combination(int n, int r) {
long long ret = factorial[n] * inv_factorial[r];
ret %= mod;
ret *= inv_factorial[n-r];
return ret % mod;
}
int main() {
GetInv(); GetFactorial();
int n; cin >> n;
long long ans = 0;
for (int i = 0; i < n; i++) {
long long c; cin >> c;
ans = (ans + combination(n-1, i) * c % mod) % mod;
}
cout << ans << endl;
return 0;
}