結果

問題 No.797 Noelちゃんとピラミッド
ユーザー polylogK
提出日時 2019-03-15 20:03:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 169,988 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-01 20:05:47
合計ジャッジ時間 4,987 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

const int MOD = 1e9 + 7;

i64 mod_pow(i64 x, int n = MOD - 2) {
	i64 ret = 1;
	while(n) {
		if(n & 1) (ret *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	return ret;
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	std::vector<i64> fact(n + 1, 1);
	for(int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD;
	
	std::function<i64 (int, int)> comb = [&](int n, int r) {
		return fact[n] * mod_pow(fact[r]) % MOD * mod_pow(fact[n - r]) % MOD;
	};
	
	int ans = 0;
	for(int i = 0; i < n; i++) (ans += a[i] * comb(n - 1, i) % MOD) %= MOD;
	
	printf("%d\n", ans);
	return 0;
}
0