結果

問題 No.1102 Remnants
ユーザー kappybarkappybar
提出日時 2020-07-03 22:01:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 170,716 KB
実行使用メモリ 28,424 KB
最終ジャッジ日時 2023-10-17 02:16:35
合計ジャッジ時間 4,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
27,088 KB
testcase_01 AC 24 ms
27,088 KB
testcase_02 AC 25 ms
27,088 KB
testcase_03 AC 25 ms
27,052 KB
testcase_04 AC 24 ms
27,052 KB
testcase_05 AC 110 ms
28,160 KB
testcase_06 AC 45 ms
27,088 KB
testcase_07 AC 166 ms
28,424 KB
testcase_08 AC 27 ms
27,112 KB
testcase_09 AC 27 ms
27,156 KB
testcase_10 AC 26 ms
27,096 KB
testcase_11 AC 28 ms
27,136 KB
testcase_12 AC 30 ms
27,160 KB
testcase_13 AC 29 ms
27,160 KB
testcase_14 AC 78 ms
27,368 KB
testcase_15 AC 57 ms
27,368 KB
testcase_16 AC 124 ms
28,160 KB
testcase_17 AC 114 ms
28,160 KB
testcase_18 AC 135 ms
28,160 KB
testcase_19 AC 59 ms
27,104 KB
testcase_20 AC 31 ms
27,088 KB
testcase_21 AC 98 ms
27,632 KB
testcase_22 AC 128 ms
27,896 KB
testcase_23 AC 105 ms
27,632 KB
testcase_24 AC 83 ms
27,368 KB
testcase_25 AC 149 ms
28,160 KB
testcase_26 AC 32 ms
27,168 KB
testcase_27 AC 57 ms
27,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

const int MAX = 1000000;
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(ll n,ll k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        k = min(k,n-k);
        ll res = 1;
        for(int i=1;i <= k;i++){
                res = (res * (n-i+1))%MOD;
        }
        
        res = (res * finv[k]) %MOD;
        return res;
}

long long modpow(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;
}


/*繰り返し二乗法でxのmod逆元を取る*/
long long inverse(long long x){
    return modpow(x,MOD-2);
}

int main(){
    COMinit();
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    ll c1 = 1;
    ll c2 = COM(k+n-1,n-1);
    rep(i,n){
        ans += ((c1 * c2)%MOD * a[i])%MOD;
        ans %= MOD;
        c1 = (c1 * (k+i+1))%MOD;
        c1 = (c1 * inverse(i+1))%MOD;
        c2 = (c2 * (n-i-1))%MOD;
        if(k+n-i-1!=0)c2 = (c2 * inverse(k+n-i-1))%MOD;
    }
    cout << ans << endl;
    return 0;
}
0