結果
| 問題 |
No.797 Noelちゃんとピラミッド
|
| コンテスト | |
| ユーザー |
Hoget157
|
| 提出日時 | 2019-03-15 22:03:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,687 bytes |
| コンパイル時間 | 1,561 ms |
| コンパイル使用メモリ | 169,496 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-01 20:59:02 |
| 合計ジャッジ時間 | 5,049 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
#define int long long
//typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int,int> P;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int mod_inv(int X){
int a = X, b = MOD, u = 1, v = 0;
while(b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if(u < 0) u += MOD;
return u;
}
vector<int> fact,factinv;
void nCr_init(int N){
N = min(N,(int)MOD);
fact.resize(N + 1);
factinv.resize(N + 1);
fact[0] = 1;
for(int i = 1;i <= N;i++) fact[i] = fact[i - 1] * i % MOD;
factinv[N] = mod_inv(fact[N]);
for(int i = N;i >= 1;i--) factinv[i - 1] = factinv[i] * i % MOD;
}
int nCr(int ncr_n,int ncr_r){
if(ncr_n >= MOD) return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD;
return ncr_r > ncr_n ? 0 : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD * factinv[ncr_r] % MOD;
}
signed main(){
int n,sum = 0;
cin >> n;
nCr_init(100010);
for(int i = 0;i < n;i++){
int a;
cin >> a;
sum = (sum + a * nCr(n - 1,i)) % MOD;
}
cout << sum << endl;
return 0;
}
Hoget157