結果

問題 No.797 Noelちゃんとピラミッド
ユーザー BwambocosBwambocos
提出日時 2019-03-15 21:38:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 167,764 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-09-14 13:11:18
合計ジャッジ時間 6,600 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 82 ms
4,540 KB
testcase_04 AC 82 ms
4,712 KB
testcase_05 AC 82 ms
4,740 KB
testcase_06 AC 82 ms
4,624 KB
testcase_07 AC 82 ms
4,736 KB
testcase_08 AC 82 ms
4,536 KB
testcase_09 AC 82 ms
4,576 KB
testcase_10 AC 82 ms
4,620 KB
testcase_11 AC 82 ms
4,540 KB
testcase_12 AC 82 ms
4,668 KB
testcase_13 AC 82 ms
4,708 KB
testcase_14 AC 82 ms
4,672 KB
testcase_15 AC 82 ms
4,656 KB
testcase_16 AC 82 ms
4,572 KB
testcase_17 AC 82 ms
4,576 KB
testcase_18 AC 82 ms
4,572 KB
testcase_19 AC 83 ms
4,724 KB
testcase_20 AC 82 ms
4,600 KB
testcase_21 AC 82 ms
4,668 KB
testcase_22 AC 82 ms
4,564 KB
testcase_23 AC 59 ms
4,380 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 50 ms
4,376 KB
testcase_26 AC 47 ms
4,380 KB
testcase_27 AC 81 ms
4,616 KB
testcase_28 AC 73 ms
4,380 KB
testcase_29 AC 12 ms
4,384 KB
testcase_30 AC 19 ms
4,376 KB
testcase_31 AC 59 ms
4,376 KB
testcase_32 AC 25 ms
4,376 KB
testcase_33 AC 49 ms
4,380 KB
testcase_34 AC 35 ms
4,376 KB
testcase_35 AC 82 ms
4,596 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 72 ms
4,384 KB
testcase_38 AC 76 ms
4,412 KB
testcase_39 AC 48 ms
4,380 KB
testcase_40 AC 10 ms
4,380 KB
testcase_41 AC 15 ms
4,376 KB
testcase_42 AC 46 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;

// ユークリッドの互除法
LL extgcd(LL a, LL b, LL &x, LL &y)
{
	LL g = a; x = 1; y = 0;
	if (b != 0)
	{
		g = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	return g;
}

// 逆元
LL mod_inverse(LL a, LL m)
{
	LL x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

// 階乗
std::vector<LL>fact;
void mod_fact(LL n, LL m)
{
	fact.resize(n + 1);
	fact[0] = 1;
	for (LL i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i%m;
}

// nCk mod p
LL mod_comb(LL n, LL k, LL m)
{
	if (n < k) return 0;
	return fact[n] * mod_inverse(fact[k] * fact[n - k] % m, m) % m;
}

int main()
{
	LL N;
	in >> N;
	std::vector<LL>a(N);
	rep(i, N) in >> a[i];

	LL ans = 0;
	mod_fact(N + 1, mod);
	rep(i, N)
	{
		LL temp = ((a[i] % mod)*mod_comb(N - 1, i, mod)) % mod;
		(ans += temp) %= mod;
	}

	out << ans << std::endl;
}
0