結果

問題 No.797 Noelちゃんとピラミッド
ユーザー Krishna SameerKrishna Sameer
提出日時 2022-10-03 17:30:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 168,176 KB
実行使用メモリ 16,608 KB
最終ジャッジ日時 2023-08-27 16:30:47
合計ジャッジ時間 5,150 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,316 KB
testcase_01 AC 16 ms
15,384 KB
testcase_02 AC 15 ms
15,316 KB
testcase_03 AC 30 ms
16,484 KB
testcase_04 AC 31 ms
16,516 KB
testcase_05 AC 31 ms
16,548 KB
testcase_06 AC 31 ms
16,516 KB
testcase_07 AC 32 ms
16,516 KB
testcase_08 AC 32 ms
16,432 KB
testcase_09 AC 31 ms
16,524 KB
testcase_10 AC 32 ms
16,456 KB
testcase_11 AC 32 ms
16,500 KB
testcase_12 AC 32 ms
16,540 KB
testcase_13 AC 32 ms
16,560 KB
testcase_14 AC 32 ms
16,504 KB
testcase_15 AC 32 ms
16,544 KB
testcase_16 AC 32 ms
16,548 KB
testcase_17 AC 31 ms
16,520 KB
testcase_18 AC 32 ms
16,500 KB
testcase_19 AC 32 ms
16,608 KB
testcase_20 AC 32 ms
16,436 KB
testcase_21 AC 32 ms
16,456 KB
testcase_22 AC 31 ms
16,500 KB
testcase_23 AC 28 ms
16,236 KB
testcase_24 AC 20 ms
15,608 KB
testcase_25 AC 26 ms
15,908 KB
testcase_26 AC 26 ms
15,972 KB
testcase_27 AC 32 ms
16,452 KB
testcase_28 AC 31 ms
16,436 KB
testcase_29 AC 19 ms
15,504 KB
testcase_30 AC 20 ms
15,544 KB
testcase_31 AC 29 ms
16,220 KB
testcase_32 AC 22 ms
15,612 KB
testcase_33 AC 27 ms
15,924 KB
testcase_34 AC 23 ms
15,696 KB
testcase_35 AC 32 ms
16,428 KB
testcase_36 AC 17 ms
15,548 KB
testcase_37 AC 29 ms
16,164 KB
testcase_38 AC 30 ms
16,460 KB
testcase_39 AC 25 ms
15,920 KB
testcase_40 AC 17 ms
15,540 KB
testcase_41 AC 18 ms
15,768 KB
testcase_42 AC 26 ms
15,896 KB
testcase_43 AC 17 ms
15,320 KB
testcase_44 AC 17 ms
15,376 KB
testcase_45 AC 16 ms
15,388 KB
testcase_46 AC 16 ms
15,332 KB
testcase_47 AC 16 ms
15,376 KB
testcase_48 AC 16 ms
15,332 KB
testcase_49 AC 16 ms
15,336 KB
testcase_50 AC 16 ms
15,520 KB
testcase_51 AC 15 ms
15,320 KB
testcase_52 AC 15 ms
15,316 KB
testcase_53 AC 16 ms
15,340 KB
testcase_54 AC 16 ms
15,368 KB
testcase_55 AC 16 ms
15,376 KB
testcase_56 AC 17 ms
15,380 KB
testcase_57 AC 15 ms
15,316 KB
testcase_58 AC 16 ms
15,368 KB
testcase_59 AC 16 ms
15,584 KB
testcase_60 AC 16 ms
15,312 KB
testcase_61 AC 15 ms
15,380 KB
testcase_62 AC 16 ms
15,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb emplace_back
#define sz(v) (int)(v.size())
#define all(v) (v.begin(),v.end())
const int32_t MAX = 510000;
const int32_t M=1e9+7;

int fac[MAX], finv[MAX], inv[MAX];


void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % M;
        inv[i] = M - inv[M%i] * (M / i) % M;
        finv[i] = finv[i - 1] * inv[i] % M;
    }
}


int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % M) % M;
}

int FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	cominit();
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0;i<n;i++)
		cin >> v[i];

	int dp[n];
	dp[0] = 1;
	for(int i = 1;i<=n;i++){
		dp[i] = (dp[i-1] * (n - i))/i % M;
	}
	// dp stores the value of ncr from r = 0 to r = n

	int ans = 0;
	for(int i = 0;i<n;i++)
	{
 		ans += v[i] * COM(n-1,i) % M;
        ans %= M;	
    }

	cout << ans << " ";
	return 0;
}
0