結果

問題 No.797 Noelちゃんとピラミッド
ユーザー misora192misora192
提出日時 2020-06-08 22:34:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,101 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 167,228 KB
実行使用メモリ 5,620 KB
最終ジャッジ日時 2023-08-27 05:40:02
合計ジャッジ時間 8,689 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,004 KB
testcase_01 AC 3 ms
5,060 KB
testcase_02 AC 4 ms
5,012 KB
testcase_03 AC 100 ms
5,400 KB
testcase_04 AC 100 ms
5,536 KB
testcase_05 AC 99 ms
5,484 KB
testcase_06 AC 99 ms
5,448 KB
testcase_07 AC 99 ms
5,336 KB
testcase_08 AC 99 ms
5,384 KB
testcase_09 AC 99 ms
5,352 KB
testcase_10 AC 99 ms
5,348 KB
testcase_11 AC 100 ms
5,352 KB
testcase_12 AC 100 ms
5,452 KB
testcase_13 AC 102 ms
5,484 KB
testcase_14 AC 100 ms
5,400 KB
testcase_15 AC 100 ms
5,424 KB
testcase_16 AC 100 ms
5,460 KB
testcase_17 AC 100 ms
5,372 KB
testcase_18 AC 100 ms
5,408 KB
testcase_19 AC 99 ms
5,372 KB
testcase_20 AC 99 ms
5,328 KB
testcase_21 AC 99 ms
5,368 KB
testcase_22 AC 99 ms
5,352 KB
testcase_23 AC 72 ms
5,196 KB
testcase_24 AC 25 ms
4,916 KB
testcase_25 AC 61 ms
5,276 KB
testcase_26 AC 58 ms
5,104 KB
testcase_27 AC 98 ms
5,464 KB
testcase_28 AC 87 ms
5,424 KB
testcase_29 AC 16 ms
5,068 KB
testcase_30 AC 24 ms
5,000 KB
testcase_31 AC 72 ms
5,184 KB
testcase_32 AC 33 ms
4,952 KB
testcase_33 AC 60 ms
5,140 KB
testcase_34 AC 43 ms
5,044 KB
testcase_35 AC 99 ms
5,620 KB
testcase_36 AC 14 ms
5,068 KB
testcase_37 AC 87 ms
5,464 KB
testcase_38 AC 91 ms
5,356 KB
testcase_39 AC 59 ms
5,320 KB
testcase_40 AC 14 ms
5,140 KB
testcase_41 AC 19 ms
5,356 KB
testcase_42 AC 57 ms
5,100 KB
testcase_43 AC 4 ms
5,216 KB
testcase_44 AC 4 ms
4,940 KB
testcase_45 AC 4 ms
5,016 KB
testcase_46 AC 4 ms
4,968 KB
testcase_47 AC 3 ms
4,932 KB
testcase_48 AC 3 ms
4,960 KB
testcase_49 AC 4 ms
4,940 KB
testcase_50 AC 4 ms
5,220 KB
testcase_51 AC 4 ms
5,116 KB
testcase_52 AC 4 ms
5,044 KB
testcase_53 AC 4 ms
5,020 KB
testcase_54 AC 4 ms
5,016 KB
testcase_55 AC 4 ms
5,148 KB
testcase_56 AC 4 ms
4,944 KB
testcase_57 AC 4 ms
4,972 KB
testcase_58 AC 3 ms
5,052 KB
testcase_59 AC 4 ms
4,988 KB
testcase_60 AC 4 ms
5,032 KB
testcase_61 AC 4 ms
5,224 KB
testcase_62 AC 4 ms
5,012 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; }

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);

	int 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