結果

問題 No.1081 和の和
ユーザー shinchanshinchan
提出日時 2020-09-23 01:17:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 198,636 KB
実行使用メモリ 8,288 KB
最終ジャッジ日時 2023-09-09 09:06:53
合計ジャッジ時間 3,176 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,116 KB
testcase_01 AC 8 ms
8,040 KB
testcase_02 AC 7 ms
8,176 KB
testcase_03 AC 7 ms
8,028 KB
testcase_04 AC 7 ms
8,140 KB
testcase_05 AC 7 ms
8,180 KB
testcase_06 AC 8 ms
8,212 KB
testcase_07 AC 8 ms
8,068 KB
testcase_08 AC 8 ms
8,288 KB
testcase_09 AC 8 ms
8,212 KB
testcase_10 AC 8 ms
8,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cominit();
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += (a[i] * com(n - 1, i)) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
0