結果

問題 No.1081 和の和
ユーザー misora192misora192
提出日時 2020-06-19 21:58:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 167,252 KB
実行使用メモリ 5,084 KB
最終ジャッジ日時 2023-09-16 14:07:11
合計ジャッジ時間 2,166 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,008 KB
testcase_01 AC 3 ms
4,904 KB
testcase_02 AC 3 ms
4,996 KB
testcase_03 AC 4 ms
4,928 KB
testcase_04 AC 4 ms
4,852 KB
testcase_05 AC 4 ms
4,864 KB
testcase_06 AC 4 ms
4,940 KB
testcase_07 AC 4 ms
5,084 KB
testcase_08 AC 3 ms
4,872 KB
testcase_09 AC 3 ms
4,868 KB
testcase_10 AC 4 ms
4,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// combination
// O(n)

const ll MOD = 1e9 + 7;
const ll max_n = 202020;
ll fact[max_n];
bool fact_init = false;

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * pow(a, b - 1) % MOD;

	ll d = pow(a, b / 2) % MOD;
	return d * d % MOD;
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2; i < max_n; i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= pow(fact[k],MOD-2);
	ret %= MOD;
	ret *= pow(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	ll ans = 0;
	rep(i, n){
		ans += comb(n-1, i) * a[i] % MOD;
		ans %= MOD;
	}

	cout << ans << endl;	
}
0