結果

問題 No.1081 和の和
ユーザー udonmanudonman
提出日時 2020-06-19 22:03:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 76,232 KB
実行使用メモリ 15,324 KB
最終ジャッジ日時 2023-09-16 14:17:44
合計ジャッジ時間 1,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
15,300 KB
testcase_01 AC 14 ms
15,168 KB
testcase_02 AC 14 ms
15,168 KB
testcase_03 AC 15 ms
15,140 KB
testcase_04 AC 14 ms
15,124 KB
testcase_05 AC 14 ms
15,160 KB
testcase_06 AC 15 ms
15,176 KB
testcase_07 AC 14 ms
15,128 KB
testcase_08 AC 15 ms
15,324 KB
testcase_09 AC 14 ms
15,180 KB
testcase_10 AC 14 ms
15,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

//ll mod = 1000000009;

const int MAX = 510000;
const int MOD = 1000000007;

long long 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 % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long 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] % MOD) % MOD;
}


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    COMinit();

    ll ans = 0;
    rep(i,n){
        ans += COM(n-1,i) * a[i] % MOD;
    }
    cout << ans % MOD << endl;
}



0