結果

問題 No.797 Noelちゃんとピラミッド
ユーザー ahe100ahe100
提出日時 2019-04-13 03:40:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 2,285 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 168,648 KB
実行使用メモリ 4,876 KB
最終ジャッジ日時 2023-10-13 09:29:32
合計ジャッジ時間 6,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 40 ms
4,616 KB
testcase_04 AC 40 ms
4,552 KB
testcase_05 AC 40 ms
4,624 KB
testcase_06 AC 42 ms
4,616 KB
testcase_07 AC 42 ms
4,624 KB
testcase_08 AC 42 ms
4,564 KB
testcase_09 AC 41 ms
4,564 KB
testcase_10 AC 43 ms
4,560 KB
testcase_11 AC 42 ms
4,556 KB
testcase_12 AC 43 ms
4,700 KB
testcase_13 AC 42 ms
4,600 KB
testcase_14 AC 42 ms
4,744 KB
testcase_15 AC 43 ms
4,684 KB
testcase_16 AC 42 ms
4,600 KB
testcase_17 AC 42 ms
4,644 KB
testcase_18 AC 40 ms
4,876 KB
testcase_19 AC 41 ms
4,632 KB
testcase_20 AC 41 ms
4,728 KB
testcase_21 AC 41 ms
4,556 KB
testcase_22 AC 41 ms
4,560 KB
testcase_23 AC 31 ms
4,384 KB
testcase_24 AC 11 ms
4,352 KB
testcase_25 AC 26 ms
4,356 KB
testcase_26 AC 24 ms
4,352 KB
testcase_27 AC 39 ms
4,716 KB
testcase_28 AC 37 ms
4,616 KB
testcase_29 AC 7 ms
4,352 KB
testcase_30 AC 11 ms
4,348 KB
testcase_31 AC 31 ms
4,352 KB
testcase_32 AC 15 ms
4,352 KB
testcase_33 AC 26 ms
4,352 KB
testcase_34 AC 19 ms
4,352 KB
testcase_35 AC 41 ms
4,624 KB
testcase_36 AC 7 ms
4,348 KB
testcase_37 AC 37 ms
4,708 KB
testcase_38 AC 39 ms
4,852 KB
testcase_39 AC 26 ms
4,484 KB
testcase_40 AC 7 ms
4,352 KB
testcase_41 AC 9 ms
4,352 KB
testcase_42 AC 25 ms
4,428 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,352 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 3 ms
4,352 KB
testcase_47 AC 3 ms
4,352 KB
testcase_48 AC 3 ms
4,352 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 3 ms
4,352 KB
testcase_51 AC 3 ms
4,352 KB
testcase_52 AC 3 ms
4,352 KB
testcase_53 AC 3 ms
4,348 KB
testcase_54 AC 3 ms
4,352 KB
testcase_55 AC 3 ms
4,348 KB
testcase_56 AC 3 ms
4,352 KB
testcase_57 AC 3 ms
4,352 KB
testcase_58 AC 3 ms
4,348 KB
testcase_59 AC 3 ms
4,348 KB
testcase_60 AC 3 ms
4,348 KB
testcase_61 AC 3 ms
4,352 KB
testcase_62 AC 3 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
AC
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

ll n,a[100010],mo=1e9+7;
mint ans=0;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	nCr_computeFactinv(100010);
}

int main(void){
	init();
	rep(i,n){
		ans+=(a[i]*nCr(n-1,i).get())%mo;
	}
	cout<<ans.get()<<endl;
	return 0;
}
0