結果

問題 No.797 Noelちゃんとピラミッド
ユーザー rhincodon66
提出日時 2019-03-15 22:44:03
言語 C++14
(gcc 8.2.0)
結果
AC  
実行時間 41 ms
コード長 784 Byte
コンパイル時間 1,334 ms
使用メモリ 8,920 KB
最終ジャッジ日時 2019-06-28 11:43:50

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
001sample.txt AC 19 ms
6,872 KB
002sample.txt AC 21 ms
6,872 KB
003sample.txt AC 20 ms
6,868 KB
LEARGE_case1.txt AC 34 ms
6,868 KB
LEARGE_case2.txt AC 33 ms
6,872 KB
LEARGE_case3.txt AC 34 ms
6,868 KB
LEARGE_case4.txt AC 34 ms
6,872 KB
LEARGE_case5.txt AC 33 ms
8,912 KB
LEARGE_case6.txt AC 32 ms
6,872 KB
LEARGE_case7.txt AC 33 ms
6,868 KB
LEARGE_case8.txt AC 33 ms
6,872 KB
LEARGE_case9.txt AC 33 ms
6,872 KB
LEARGE_case10.txt AC 33 ms
6,872 KB
LEARGE_case11.txt AC 34 ms
6,868 KB
LEARGE_case12.txt AC 33 ms
6,868 KB
LEARGE_case13.txt AC 33 ms
6,872 KB
LEARGE_case14.txt AC 33 ms
6,868 KB
LEARGE_case15.txt AC 34 ms
6,868 KB
LEARGE_case16.txt AC 33 ms
6,872 KB
LEARGE_case17.txt AC 32 ms
6,872 KB
LEARGE_case18.txt AC 41 ms
6,872 KB
LEARGE_case19.txt AC 33 ms
6,868 KB
LEARGE_case20.txt AC 33 ms
6,872 KB
RANDOM_case1.txt AC 30 ms
6,872 KB
RANDOM_case2.txt AC 23 ms
6,872 KB
RANDOM_case3.txt AC 27 ms
6,868 KB
RANDOM_case4.txt AC 28 ms
6,868 KB
RANDOM_case5.txt AC 33 ms
6,872 KB
RANDOM_case6.txt AC 31 ms
6,872 KB
RANDOM_case7.txt AC 23 ms
6,868 KB
RANDOM_case8.txt AC 24 ms
6,872 KB
RANDOM_case9.txt AC 29 ms
6,868 KB
RANDOM_case10.txt AC 23 ms
6,868 KB
RANDOM_case11.txt AC 28 ms
6,872 KB
RANDOM_case12.txt AC 26 ms
6,872 KB
RANDOM_case13.txt AC 32 ms
6,872 KB
RANDOM_case14.txt AC 22 ms
6,868 KB
RANDOM_case15.txt AC 32 ms
6,872 KB
RANDOM_case16.txt AC 34 ms
6,868 KB
RANDOM_case17.txt AC 28 ms
6,872 KB
RANDOM_case18.txt AC 21 ms
6,872 KB
RANDOM_case19.txt AC 22 ms
6,872 KB
RANDOM_case20.txt AC 27 ms
6,872 KB
SMALL_case1.txt AC 20 ms
6,868 KB
SMALL_case2.txt AC 19 ms
6,868 KB
SMALL_case3.txt AC 21 ms
6,872 KB
SMALL_case4.txt AC 20 ms
6,872 KB
SMALL_case5.txt AC 20 ms
6,868 KB
SMALL_case6.txt AC 19 ms
6,868 KB
SMALL_case7.txt AC 21 ms
6,872 KB
SMALL_case8.txt AC 20 ms
8,920 KB
SMALL_case9.txt AC 20 ms
6,872 KB
SMALL_case10.txt AC 20 ms
6,868 KB
SMALL_case11.txt AC 21 ms
6,868 KB
SMALL_case12.txt AC 21 ms
6,872 KB
SMALL_case13.txt AC 20 ms
6,868 KB
SMALL_case14.txt AC 20 ms
6,872 KB
SMALL_case15.txt AC 20 ms
6,872 KB
SMALL_case16.txt AC 19 ms
8,916 KB
SMALL_case17.txt AC 19 ms
6,872 KB
SMALL_case18.txt AC 20 ms
6,868 KB
SMALL_case19.txt AC 20 ms
6,868 KB
SMALL_case20.txt AC 20 ms
8,912 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