結果

問題 No.797 Noelちゃんとピラミッド
ユーザー gazellegazelle
提出日時 2019-03-15 22:25:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,003 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 119,396 KB
実行使用メモリ 11,676 KB
最終ジャッジ日時 2023-09-14 13:45:48
合計ジャッジ時間 5,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,700 KB
testcase_01 AC 10 ms
10,680 KB
testcase_02 AC 10 ms
10,556 KB
testcase_03 AC 63 ms
11,484 KB
testcase_04 AC 64 ms
11,540 KB
testcase_05 AC 63 ms
11,524 KB
testcase_06 AC 63 ms
11,588 KB
testcase_07 AC 63 ms
11,592 KB
testcase_08 AC 64 ms
11,484 KB
testcase_09 AC 65 ms
11,672 KB
testcase_10 AC 63 ms
11,592 KB
testcase_11 AC 63 ms
11,592 KB
testcase_12 AC 63 ms
11,532 KB
testcase_13 AC 63 ms
11,484 KB
testcase_14 AC 63 ms
11,468 KB
testcase_15 AC 63 ms
11,608 KB
testcase_16 AC 63 ms
11,476 KB
testcase_17 AC 63 ms
11,468 KB
testcase_18 AC 64 ms
11,676 KB
testcase_19 AC 64 ms
11,464 KB
testcase_20 AC 63 ms
11,580 KB
testcase_21 AC 64 ms
11,572 KB
testcase_22 AC 64 ms
11,584 KB
testcase_23 AC 48 ms
11,588 KB
testcase_24 AC 22 ms
11,068 KB
testcase_25 AC 42 ms
11,180 KB
testcase_26 AC 40 ms
11,524 KB
testcase_27 AC 62 ms
11,476 KB
testcase_28 AC 57 ms
11,464 KB
testcase_29 AC 17 ms
11,148 KB
testcase_30 AC 21 ms
11,056 KB
testcase_31 AC 48 ms
11,200 KB
testcase_32 AC 26 ms
10,964 KB
testcase_33 AC 42 ms
11,344 KB
testcase_34 AC 32 ms
11,304 KB
testcase_35 AC 64 ms
11,480 KB
testcase_36 AC 16 ms
10,992 KB
testcase_37 AC 57 ms
11,544 KB
testcase_38 AC 60 ms
11,544 KB
testcase_39 AC 40 ms
11,344 KB
testcase_40 AC 15 ms
11,016 KB
testcase_41 AC 18 ms
11,116 KB
testcase_42 AC 39 ms
11,280 KB
testcase_43 AC 10 ms
10,628 KB
testcase_44 AC 10 ms
10,516 KB
testcase_45 AC 10 ms
10,652 KB
testcase_46 AC 10 ms
10,676 KB
testcase_47 AC 10 ms
10,512 KB
testcase_48 AC 11 ms
10,540 KB
testcase_49 AC 10 ms
10,628 KB
testcase_50 AC 10 ms
10,504 KB
testcase_51 AC 11 ms
10,756 KB
testcase_52 AC 11 ms
10,592 KB
testcase_53 AC 10 ms
10,744 KB
testcase_54 AC 11 ms
10,696 KB
testcase_55 AC 10 ms
10,592 KB
testcase_56 AC 10 ms
10,744 KB
testcase_57 AC 10 ms
10,580 KB
testcase_58 AC 10 ms
10,664 KB
testcase_59 AC 10 ms
10,628 KB
testcase_60 AC 10 ms
10,608 KB
testcase_61 AC 10 ms
10,656 KB
testcase_62 AC 10 ms
10,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

#define MAX_N 1000000
long long extgcd(long long a, long long b, long long& x, long long& y) {
	long long d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}
long long mod_inverse(long long a, long long m) {
	long long x, y;
	if(extgcd(a, m, x, y) == 1) return (m + x % m) % m;
	else return -1;
}
vector<long long> fact(MAX_N+1, INF);
long long mod_fact(long long n, long long& e) {
	if(fact[0] == INF) {
		fact[0]=1;
		if(MAX_N != 0) fact[1]=1;
		for(ll i = 2; i <= MAX_N; ++i) {
			fact[i] = (fact[i-1] * i) % MOD;
		}
	}
	e = 0;
	if(n == 0) return 1;
	long long res = mod_fact(n / MOD, e);
	e += n / MOD;
	if((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD;
	return (res * fact[n % MOD]) % MOD;
}
// return nCk
long long mod_comb(long long n, long long k) {
	if(n < 0 || k < 0 || n < k) return 0;
	long long e1, e2, e3;
	long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3);
	if(e1 > e2 + e3) return 0;
	return (a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD;
}

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 += a[i] * mod_comb(n - 1, i);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */
0