結果
| 問題 |
No.797 Noelちゃんとピラミッド
|
| コンテスト | |
| ユーザー |
wheson
|
| 提出日時 | 2019-03-15 22:46:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 1,689 bytes |
| コンパイル時間 | 1,599 ms |
| コンパイル使用メモリ | 170,240 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 21:21:55 |
| 合計ジャッジ時間 | 5,110 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 60 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
class Countings{
private:
int mod;
vector<long long> factList, invList;
long long Pow(long long x, long long n);
public:
Countings(int sz, int mod);
long long Permutation(int n, int r);
long long Combination(int n, int r);
long long HomogeneousProduct(int n, int r);
};
Countings::Countings(int sz, int mod) : mod(mod), factList(sz + 1), invList(sz + 1) {
factList[0] = 1;
for(int i = 1; i < factList.size(); i++) {
factList[i] = factList[i - 1] * i % mod;
}
invList[sz] = Pow(factList[sz], mod - 2);
for(int i = sz - 1; i >= 0; i--) {
invList[i] = invList[i + 1] * (i + 1) % mod;
}
}
long long Countings::Pow(long long x, long long n){
long long ret = 1;
while(n > 0) {
if(n & 1) ret = ret * x % mod;
x = x * x % mod;
n >>= 1;
}
return ret;
}
long long Countings::Permutation(int n, int r){
if(r < 0 || n < r) return 0;
return factList[n] * invList[n - r] % mod;
}
long long Countings::Combination(int n, int r){
if(r < 0 || n < r) return 0;
return factList[n] * invList[r] % mod * invList[n - r] % mod;
}
long long Countings::HomogeneousProduct(int n, int r){
if(n < 0 || r < 0) return 0;
return (r == 0 ? 1 : Combination(n + r - 1, r));
}
int main(){
int n;
cin >> n;
vector<LL> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
Countings ct(n, (int)(1e9 + 7));
LL ans = 0;
const LL MOD = 1e9 + 7;
for(int i = 0; i < n; i++){
ans = (ans + a[i] * ct.Combination(n-1, i)) % MOD;
}
cout << ans << endl;
}
wheson