結果

問題 No.797 Noelちゃんとピラミッド
ユーザー rhincodon66rhincodon66
提出日時 2019-03-15 22:44:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 166,572 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2023-09-14 13:55:42
合計ジャッジ時間 5,469 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
5,000 KB
testcase_01 AC 16 ms
4,904 KB
testcase_02 AC 16 ms
4,876 KB
testcase_03 AC 30 ms
5,392 KB
testcase_04 AC 29 ms
5,420 KB
testcase_05 AC 29 ms
5,296 KB
testcase_06 AC 30 ms
5,436 KB
testcase_07 AC 29 ms
5,432 KB
testcase_08 AC 29 ms
5,348 KB
testcase_09 AC 30 ms
5,392 KB
testcase_10 AC 30 ms
5,272 KB
testcase_11 AC 29 ms
5,288 KB
testcase_12 AC 29 ms
5,328 KB
testcase_13 AC 29 ms
5,396 KB
testcase_14 AC 29 ms
5,348 KB
testcase_15 AC 29 ms
5,424 KB
testcase_16 AC 29 ms
5,388 KB
testcase_17 AC 29 ms
5,332 KB
testcase_18 AC 29 ms
5,344 KB
testcase_19 AC 29 ms
5,392 KB
testcase_20 AC 29 ms
5,296 KB
testcase_21 AC 30 ms
5,272 KB
testcase_22 AC 29 ms
5,388 KB
testcase_23 AC 25 ms
5,292 KB
testcase_24 AC 19 ms
4,940 KB
testcase_25 AC 25 ms
5,128 KB
testcase_26 AC 24 ms
5,128 KB
testcase_27 AC 29 ms
5,472 KB
testcase_28 AC 27 ms
5,332 KB
testcase_29 AC 19 ms
4,996 KB
testcase_30 AC 19 ms
4,908 KB
testcase_31 AC 26 ms
5,064 KB
testcase_32 AC 20 ms
4,940 KB
testcase_33 AC 24 ms
5,152 KB
testcase_34 AC 22 ms
4,988 KB
testcase_35 AC 29 ms
5,392 KB
testcase_36 AC 18 ms
4,928 KB
testcase_37 AC 28 ms
5,324 KB
testcase_38 AC 29 ms
5,332 KB
testcase_39 AC 24 ms
5,068 KB
testcase_40 AC 18 ms
4,980 KB
testcase_41 AC 19 ms
5,032 KB
testcase_42 AC 24 ms
5,224 KB
testcase_43 AC 16 ms
4,904 KB
testcase_44 AC 16 ms
4,916 KB
testcase_45 AC 16 ms
4,980 KB
testcase_46 AC 16 ms
4,828 KB
testcase_47 AC 17 ms
4,916 KB
testcase_48 AC 16 ms
5,060 KB
testcase_49 AC 17 ms
4,984 KB
testcase_50 AC 17 ms
4,916 KB
testcase_51 AC 16 ms
4,980 KB
testcase_52 AC 16 ms
4,852 KB
testcase_53 AC 17 ms
4,944 KB
testcase_54 AC 16 ms
4,876 KB
testcase_55 AC 16 ms
4,852 KB
testcase_56 AC 16 ms
4,992 KB
testcase_57 AC 16 ms
4,828 KB
testcase_58 AC 17 ms
4,984 KB
testcase_59 AC 16 ms
4,996 KB
testcase_60 AC 17 ms
4,904 KB
testcase_61 AC 16 ms
4,948 KB
testcase_62 AC 16 ms
4,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const ll mod=1000000007;

ll f[100001],rf[100001];

ll inv(ll x){
	ll ret=1;
	ll k=mod-2;
	ll y=x;
	while(k){
		if(k&1) ret=(ret*y)%mod;
		y=(y*y)%mod;
		k/=2;
	}
	return ret;
}

void init(){
	f[0]=1;
	for(int i=1;i<=100000;++i) f[i]=(f[i-1]*i)%mod;
	rep(i,100001) rf[i]=inv(f[i]);
}

ll calc(int n,int k){
	ll a=f[n];
	ll b=rf[n-k];
	ll c=rf[k];
	ll bc=(b*c)%mod;
	return (a*bc)%mod;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans=0;
	init();
	rep(i,n){
		ans+=(calc(n-1,i)*a.at(i))%mod;
		ans%=mod;
	}
	cout << ans << endl;
}
0